java - Validating for Binary codes and repeating program without infinite loop -
i assigned make program converts binary decimal. got part done no problems have validate user inputs make sure put in binary or else should "try again" have keep program repeating using letter "y/y" continue or else exists without using infinite loop. have no idea how without infinite loop. thank you
import java.util.scanner; class quiz4 { public static void main(string args[]){ scanner input = new scanner( system.in ); system.out.print("enter binary number: "); string binarystring =input.nextline(); system.out.println("output: "+integer.parseint(binarystring,2)); } }
ok, you've posted code, need read (and understand) requirements.
judging on post, concrete requirement not use "infinite loop" - interpret mean i'm allowed use conditional loop.
so, assuming understand requirements, would:
- wrap existing code in do/while loop, since want evaluate @ end of execution.
- write code read keyboard.
- exit above loop when keyboard input appropriate (e.g.
(!myvar.tolower().equals("y"))
).
feel free write code & update post, , if needed, i'll update answer. apologies, writing code is, in opinion, both against spirit of , counter-productive studies.
however, way solve problem, recursion. if teacher asking solve this problem recursion, consider finding teacher.
Comments
Post a Comment