java - How to implement continuous String loop -
i'm new java, got stuck following:
create program output console names , from. make program ask user information. advanced assignment: change program runs in continuous loop, asking user name , from, , outputting console. if user types in "x" either name or from, terminate loop.
i implemented first part, having trouble advanced assignment. can please give me hint, thank you!
import java.util.scanner; public class mainclass { public static void main(string[] args) { scanner myscan = new scanner(system.in); system.out.println("enter name"); string myname = myscan.next(); system.out.println("enter location"); string mylocation = myscan.next(); system.out.println("your name "+ myname + " , location " + mylocation); } }
you nest contents of main method in continuous loop , check inputs "x", if either "x" "break" out of loop.
public static void main(string[] args) { scanner myscan = new scanner(system.in); while(true) { system.out.println("enter name"); string myname = myscan.next(); system.out.println("enter location"); string mylocation = myscan.next(); if(myname.equals("x") || mylocation.equals("x")){ break; } system.out.println("your name " + myname + " , location " + mylocation); } }
Comments
Post a Comment