java - Cannot find string -


i'm messing around code see can , can't , i'm creating simple log in program , reason can't seem find 1 of strings. here's code:

import java.util.scanner;  public class login {     public static void main(string[] args) {         scanner input = new scanner(system.in);          system.out.print("username: ");         string user = input.next();         system.out.print('\f');          while (true) {             system.out.print("pass: ");             string pass = input.next();             system.out.print('\f');              system.out.print("password again: ");             string pass2 = input.next();             system.out.print('\f');              if (pass.equals(pass2)) {                 system.out.println("*passwords match*");                 system.out.println("");                 break;             } else if (!pass.equals(pass2)) {                  system.out.println("*passwords don't match, please try again*");                  system.out.println("");             }          }         system.out.println("user: " + user);         system.out.println("pass: " + pass);     } } 

it can't find string pass. don't know if it's reserved word or not when tried changing string password instead of pass still couldn't find it. nice

you using pass outside of can used. if declare within main method, code work. basically, being used outside of scope of while loop must initialized somewhere. stated, don't have worry pass2 being declared elsewhere since main functionality resides purely within scope of loop

import java.util.scanner;  public class login {     public static void main(string[] args) {         scanner input = new scanner(system.in);         string pass,user;         system.out.print("username: ");         user = input.next();         system.out.print('\f');          while (true) {             system.out.print("pass: ");             pass = input.next();             system.out.print('\f');              system.out.print("password again: ");             string pass2 = input.next();             system.out.print('\f');              if (pass.equals(pass2)) {                 system.out.println("*passwords match*");                 system.out.println("");                 break;             } else if (!pass.equals(pass2)) {                  system.out.println("*passwords don't match, please try again*");                  system.out.println("");             }          }         system.out.println("user: " + user);         system.out.println("pass: " + pass);     } } 

Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -