Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Do while error, I'm going crazy

 
bue curt
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi



So I want to an option for the user if she/he still wants to input another number. But It just would not work

We are not allowed to use "equalsIgnoreCase", just do while, and I cant make it work,

PLEASE HELP
 
John de Michele
Rancher
Posts: 600
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bue:

Can you give us the stack trace? That would be very helpful in diagnosing your problem.

John.
 
bue curt
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here it is

 
Athul Shetty
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Bue,

I think you are missing one more try block, thats y you are getting above error.

Regards
Shetty
 
John de Michele
Rancher
Posts: 600
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Athul:

Please use real words.

John.
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think correcting your indentation would help keep you from going crazy -- and might illustrate the problem.
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And saying what the error is *when you post* would be helpful.
 
R Johnson
Greenhorn
Posts: 28
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I believe what Athul was trying to say is there is a try at line 16 and is caught at line 33 with catch but there is another catch at line 158 with no other try in the code. I'm not currently at a computer that has an IDE available to quickly test this, but I've searched the code twice and just don't see more than one try statement. However, I am new to Java and I feel since the catch statements are of seperate types one is IOException and the other just Exception they should both be able to be executed with the single try statement. Is it their placeing? Or perhaps too many brackets }? If I had to guess once you catch the try statement you probably should go ahead and declare each catch right then because everything after the catch is no longer affected by the try statement so there would be no way to catch it perse'.
 
bue curt
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Help please, the program would just give error after error. it says that ";" is expected.


 
sujith Acharya
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Bue,

I don't see any try block for the second catch block

that you have written
 
maitrayi vasishtha
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Remove catch from outside while and put the following statements in try block and write catch block for it.
answer = dataIn.readLine();
x=Integer.parseInt(answer);

I have done this for you as foll. Its working fine.

I have not read your logic completely but I guess you should use array to store the numbers_in_words and find out the index to search and get the the number in words. This logic will work fine for you.



 
bue curt
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
maitrayi vasishtha wrote:Remove catch from outside while and put the following statements in try block and write catch block for it.
answer = dataIn.readLine();
x=Integer.parseInt(answer);

I have done this for you as foll. Its working fine.

I have not read your logic completely but I guess you should use array to store the numbers_in_words and find out the index to search and get the the number in words. This logic will work fine for you.






meh, it did not work.



Im still trying to figure it out
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Reformatting your code with a decent editor will show you that the last "break" is misplaced.
 
Sherif Shehab
Ranch Hand
Posts: 485
Android Eclipse IDE Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
bue curt wrote:
maitrayi vasishtha wrote:Remove catch from outside while and put the following statements in try block and write catch block for it.
answer = dataIn.readLine();
x=Integer.parseInt(answer);

I have done this for you as foll. Its working fine.

I have not read your logic completely but I guess you should use array to store the numbers_in_words and find out the index to search and get the the number in words. This logic will work fine for you.






meh, it did not work.



Im still trying to figure it out


Bue ,

Put the break in line 147 inside the case 9 , then it will work fine
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic