java - scanner next() Inputmismatch exception ..used nextLine() after nextInt() -


this question has answer here:

i couldn't find bug. used nextline() after reading nextint() still next() not reading word("update"). missing?

input read:

    2     4 5     update 2 2 2 4     query 1 1 1 3 3 3     update 1 1 1 23     query 2 2 2 4 4 4     query 1 1 1 3 3 3     2 4     update 2 2 2 1     query 1 1 1 1 1 1     query 1 1 1 2 2 2     query 2 2 2 2 2 2 

my code:

   scanner sc = new scanner(system.in);         int t = sc.nextint();         for(int i=0 ; i<t ; i++){             int n = sc.nextint();             int m = sc.nextint();             sc. nextline ();             system.out.println(n+ " " + m);             for(int j=0 ; j<m ; j++){                 string q = sc.next(); // tried (string)sc.next();                  if(q == "update"){                     int x = sc.nextint();                     int y = sc.nextint();                     int z = sc.nextint();                     int val = sc.nextint();                     sc.nextline();                     system.out.println(x+ " " + y + " "+ z + " "+ val);                 }                 else if(q == "query"){                     int x1 = sc.nextint()-1;                     int y1 = sc.nextint()-1;                     int z1 = sc.nextint()-1;                      int x2 = sc.nextint();                     int y2 = sc.nextint();                     int z2 = sc.nextint();                     sc.nextline();                    system.out.println(x1+ " " + y1 + " "+ z1 + " "+ x2+ " " + y2 + " "+ z2);                 }               }         } 

string comparisons in java made .equals

replace code for

if(q.equals("update")){ 

Comments

Popular posts from this blog

yii2 - Yii 2 Running a Cron in the basic template -

asp.net - 'System.Web.HttpContext' does not contain a definition for 'GetOwinContext' Mystery -

mercurial graft feature, can it copy? -