-4

I'm new in Java and more familiar with c++

import java.util.Scanner; 
class Test{ 
public static void main(String args[]){
Scanner sc=new Scanner(System.in); 
 System.out.println("Pick option:\n 1-Option one\n 2-Option two");
 int x= sc.nextInt();
if (x=1);
{
System.out.println("You select option one");
}
else if(x=2);{
        System.out.println("You select option two");
}
else{
System.out.println("Please select option one or two by typing 1 or 2");}                 

} 
}

What should look like:

Pick option:

1- Option one
2- Option two

//User type 1:

You select option one.

//User type 2:

You select option two.

//User type anything else

Please select option one or two by typing 1 or 2.

How i can do that with java code.

Feras Al Sous
  • 1,073
  • 1
  • 12
  • 23
RipzorM97
  • 13
  • 1

1 Answers1

0

You should use == to copmare not use = and ; after if statment not correct.

You can see the code after edit like this:

    import java.util.Scanner; 
    class Test{ 
    public static void main(String args[]){
    Scanner sc=new Scanner(System.in); 
     System.out.println("Pick option:\n 1-Option one\n 2-Option two :");
     int x= sc.nextInt();
    if (x==1)
    {
    System.out.println("You select option one");
    }
    else if(x==2){
            System.out.println("You select option two");
    }
    else{
    System.out.println("Please select option one or two by typing 1 or 2");
}                 

    } 
    }
Feras Al Sous
  • 1,073
  • 1
  • 12
  • 23