• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Do while error, I'm going crazy

 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Rancher
Posts: 600
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here it is

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Athul:

Please use real words.

John.
 
Sheriff
Posts: 11343
Mac Safari Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think correcting your indentation would help keep you from going crazy -- and might illustrate the problem.
 
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
And saying what the error is *when you post* would be helpful.
 
Greenhorn
Posts: 28
Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


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


 
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Bue,

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

that you have written
 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Reformatting your code with a decent editor will show you that the last "break" is misplaced.
 
Ranch Hand
Posts: 493
Android Eclipse IDE Oracle
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic