473,387 Members | 1,892 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

output problems

I created a program to read in a file, transform the given roman numeral, double the numeral, and then output the new roman numeral.

I am not even sure yet if my Roman decrpyt and encrpytion is right because nothing is outputting into the roman.out file??

Expand|Select|Wrap|Line Numbers
  1. public class Roman {
  2.  
  3.         public void decryptEncrypt (String inputFileName, String outputFileName)
  4.         {
  5.             try {
  6.                 FileReader reader = new FileReader(inputFileName) ;
  7.                 Scanner in = new Scanner(reader) ;
  8.                 PrintWriter out = new PrintWriter(outputFileName) ;
  9.  
  10.  
  11.                 String romanout = " ";
  12.                 while (in.hasNext( ) ){
  13.                     String roman = in.nextLine( ) ;
  14.                     //out.print(roman);
  15.                     for(int i = 0; i < roman.length(); i++) {
  16.                         int num = 0;
  17.                         char digit = ' ';
  18.                         digit = roman.charAt(i);
  19.                         while(digit != -1){
  20.                             if(digit == 'I'){
  21.                                 num++;
  22.                                 if(digit == 'V'){
  23.                                     num = num + 3;
  24.                                 }
  25.                                 else if(digit == 'X'){
  26.                                     num = num + 8;
  27.                                 }
  28.                             }
  29.                             if(digit == 'V'){
  30.                                 num = num + 5;
  31.                             }
  32.                             if(digit == 'X'){
  33.                                 num = num + 10;
  34.                                 if(digit == 'L'){
  35.                                     num = num + 30;
  36.                                 }
  37.                                 else if(digit == 'C'){
  38.                                     num = num + 80;
  39.                                 }
  40.                             }
  41.                             if(digit == 'L'){
  42.                                 num = num + 50;
  43.                             }
  44.                             if(digit == 'C'){
  45.                                 num = num + 100;
  46.                             }
  47.  
  48.                         }
  49.  
  50.             System.out.println(num);    
  51.                             num = num * 2;
  52.             //System.out.println(num);
  53.  
  54.                     while(num > 0){
  55.                             if(num > 100){
  56.                                 num = num - 100;
  57.                                 romanout = romanout + "C";
  58.                             }
  59.                             if(num == 90){
  60.                                 num = num - 90;
  61.                                 romanout = romanout + "XC";
  62.                             }
  63.                             if(num > 50){
  64.                                 num = num - 50;
  65.                                 romanout = romanout + "L";
  66.                             }
  67.                             if(num == 40){
  68.                                 num = num - 40;
  69.                                 romanout = romanout + "XL";
  70.                             }
  71.                             if(num > 10){
  72.                                 num = num - 10;
  73.                                 romanout = romanout + "X";
  74.                             }
  75.                             if(num == 9){
  76.                                 num = num - 9;
  77.                                 romanout = romanout + "IX";
  78.                             }
  79.                             if(num > 5){
  80.                                 num = num - 5;
  81.                                 romanout = romanout + "V";
  82.                             }
  83.                             if(num == 4){
  84.                                 num = num - 4;
  85.                                 romanout = romanout + "IV";
  86.                             }
  87.                             if(num > 1){
  88.                                 num = num - 1;
  89.                                 romanout = romanout + "I";
  90.                             }
  91.                     }
  92.                     out.print(roman);
  93.                     out.print(romanout);
  94.                     }
  95.  
  96.                 }
  97.                 in.close( ) ;
  98.                 out.close( ) ;    
  99.                 }
  100.             catch(IOException e)
  101.             {
  102.                 System.out.println(e) ;
  103.             }
  104.         }
  105.  
  106.         public static void main(String [] args){    
  107.             Roman reader = new Roman( ) ;
  108.             reader.decryptEncrypt("roman.in", "roman.out") ;    
  109.         }
  110. }
Jun 18 '09 #1
1 1409
JosAH
11,448 Expert 8TB
In the body of your while loop (starting at line #19) you never re-assign a value to variable digit so if it wasn't equal to -1 to start with that loop never terminates.

kind regards,

Jos
Jun 18 '09 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

13
by: Varun | last post by:
Hi Friends, Department of Information Technology, Madras Institute of Technology, Anna University, India is conducting a technical symposium, Samhita. As a part of samhita, an Online Programming...
11
by: Etienne Charland | last post by:
Hi, I have a solution containing 6 C# projects; 1 WinForms project and 5 class libraries. I didn't have any problems until recently. I added a new project containing reports. I am using...
4
by: Mountain Bikn' Guy | last post by:
I am having serious problems with the following IDE bug: Could not write to output file 'x.dll' -- 'The process cannot access the file because it is being used by another process. ' and BUG:...
0
by: Prasad Dannani | last post by:
Hi, I have some problems in reading xml data using webrequest, response and dataset objects. This program i am executing from last 6 months its worked fine. but now its throwing some exceptions....
2
by: ViperDK | last post by:
What is the best way for that? I store all Data in the original form in the Database. To prevent output fields (especially the fields everyone can use) to do bad things like killing the...
5
by: Verane | last post by:
Hi, I have read the thread named "Could not copy temporary files to the output directory" on this newsgroup. And I have the same symptoms on my machine. But I didn't find any solution suitable for...
2
by: njr | last post by:
Having copied a number of folders from my development PC (XP) to a development server (W2003) and installed them under wwwroot (and created applications in IIS) I have problems when I include the...
6
by: Peter Strøiman | last post by:
Hi. I have a situation where I have a web project and a class library in the same solution. The web project uses the class library. Therefore, I created a "project reference" in the web project...
1
by: Andrew | last post by:
I'm adding this as it to me a while to figure out all the pieces to be able to do this without using Microsoft.Office.Interop which caused me problems on the web-server. Streaming is the easy...
10
by: Flavio | last post by:
Hi, I try to write here because maybe my problem is a common one. I have a rather complicated multithreaded program, which uses the POSIX pthread standard. A master routine calls a series of...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.