Saturday, September 30, 2017

& Operator

Challenge: Write a program that reads three numbers and prints “all the same” if they are all the same, “all different” if they are all different, and “neither” otherwise.

Solution:
import java.util.Scanner;

public class lab4_3
{
public static void main(String []args)
{
//double a=2,b=1;
Scanner in= new Scanner(System.in);   
//int x=0;//b=0;//b=1;
System.out.println("Please enter three numbers");
int x=in.nextInt();

int y=in.nextInt();




int z=in.nextInt();

if (x==y && y==z && z==x)
{
System.out.println("All the same!");
}
else if(x!=y && y!=z && z!=x)
{
System.out.println("All different!");
}

else
{
System.out.println("Neither");
}

}
}

No comments:

Post a Comment