1
Help with my code?
NOTE THAT THIS IS NOT MINECRAFT MOD CODE!
Ok so I am a newbie at java and I wanted to make a simple password program, but everytime I run my code nomatter what it denies me, even if I type the right password.
Heres its code:
MAIN CLASS/METHOD:
import java.util.Scanner;
public class Mainclass {
public static void main(String[] args) {
System.out.println("What is the password?");
Scanner pass = new Scanner(System.in);
String x = pass.nextLine();
Pro ProObject = new Pro();
ProObject.beg(x);
}
}
2ND CLASS/METHOD:
import java.util.Scanner;
public class Pro {
public static void beg(String x) {
if (x == "password"){
System.out.println("Access granted");
}else{
System.out.println("Access denied");
Scanner y = new Scanner(System.in);
System.out.println("Press <Enter> to close");
System.out.println(y.nextLine());
}
}
}
Help?
Ok so I am a newbie at java and I wanted to make a simple password program, but everytime I run my code nomatter what it denies me, even if I type the right password.
Heres its code:
MAIN CLASS/METHOD:
import java.util.Scanner;
public class Mainclass {
public static void main(String[] args) {
System.out.println("What is the password?");
Scanner pass = new Scanner(System.in);
String x = pass.nextLine();
Pro ProObject = new Pro();
ProObject.beg(x);
}
}
2ND CLASS/METHOD:
import java.util.Scanner;
public class Pro {
public static void beg(String x) {
if (x == "password"){
System.out.println("Access granted");
}else{
System.out.println("Access denied");
Scanner y = new Scanner(System.in);
System.out.println("Press <Enter> to close");
System.out.println(y.nextLine());
}
}
}
Help?
Create an account or sign in to comment.