If statement doesn't pass

0 Halcyon Abraham Ramirez · September 2, 2015
Hi everyone Im a complete java noob. although not a programming noob but a Java noob

package first;
import java.util.Scanner;

public class apples {

public static void main(String args[]) {
Scanner cyon = new Scanner(System.in);
System.out.print("what is your name?");
String name = cyon.nextLine();
System.out.print("what is your age?");
int age = Integer.parseInt(cyon.nextLine());

if(name == "cyon" && age < 21){
System.out.println("hello" + name);

else if(name != "cyon" && age > 21){
System.out.println("Access denied");




the if statement never passes if you type in "cyon" and the age is less than 21

It should be pretty straight forward right? but why?

Post a Reply


Oldest  Newest  Rating
0 Halcyon Abraham Ramirez · September 2, 2015
why use can't we use ==? so when do we use == and instead of .equals? and when do we use .equals instead of ==?
  • 1

Java / Android Development


Very popular language used to create desktop applications, website applets, and Android apps.

Bucky Roberts Administrator