java - Adding a break to stop a loop -


i have code requires break after successful authentication, not sure add this. have tried adding after loop , successful authentication accepted can't seem working correctly.

one other slight problem @ line;

system.out.println("..." + i); 

says not in main method code written on pc @ work , later added original code.

here code;

public class elevator {  static scanner console = new scanner(system.in);  public static void main(string[] args) {      final int userid = 5555;      final int password = 1234;     final int studentnumber = 22334455;      int entereduserid;      int enteredpassword;     int enteredstudentnumber;     (int s = 0; s <= 3; s++) {          if (s < 3) {              system.out.println("enter userid access lift;");              entereduserid = console.nextint();             system.out.println("your userid ==> " + entereduserid);             system.out.println("enter password authenticate login;");             enteredpassword = console.nextint();             system.out.println("password entered ==> " + enteredpassword);             system.out.println("enter student number finalise login , authentication;");             enteredstudentnumber = console.nextint();             system.out.println("student number entered ==> " + enteredstudentnumber);             if (userid == entereduserid && (password == enteredpassword)                      && (studentnumber == enteredstudentnumber)) {                 system.out.println("athentication complete!");                 system.out.println("***elevator access granted!***");                 system.out.println("welcome...");  //break goes here?              } else {                 system.out.println("wrong userid, password or student number. please try again.");              }         } else {             system.out.println("3 incorrect enteries detected. access denied!");          }     } }       private int currentfloor;      public elevator() {         currentfloor = 0;     }      public void selectfloor() {         scanner scnr = new scanner(system.in);         int newfloor;          system.out.println("enter destination floor ==> ");         newfloor = scnr.nextint();         if (newfloor > 7 || newfloor < 0) {             system.out.println("invalid floor entry");         }          else {               int direction = 0;             if(currentfloor < newfloor){                 direction = 1;              } else if (currentfloor > newfloor) {                 direction = -1; ;             } else {                 direction = 0;              }             (; currentfloor != newfloor; currentfloor += newfloor)                 system.out.println("..." + i);                 system.out.println("elevator has arrived!");         }     }      public void firealarm() {         system.out.println("***fire alarm*** please exit building safely.");   }  } 

edit

so added break; code expected seemed work after declaring i, instead changed currentfloor. authentication system works fine, next part of code not seem run after successful authentication. not given errors, code not run. have feeling has bracket placement, can't figure out problem is.

break keyword exit looping, think need here continue.

continue break current process in loop , start next loop operation.

and this:

system.out.println("..." + i); 

you haven't declared i variable in setfloor method scoop.


Comments

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -