207k views
3 votes
write a java program using switch that allow the user to input length and width and check if it is square or rectangle.

User KH Kim
by
5.5k points

1 Answer

3 votes

import java.util.Scanner;

class check_rectorsq {

public static void main(String[] args) {

System.out.println("Enter length and width: ");

Scanner idx = new Scanner(System.in);

int x = idx.nextInt();

int y = idx.nextInt();

int f = (x==y) ? 1 : 0;

switch(f) {

case 1:

System.out.println("This is a square!");

break;

case 0:

System.out.println("This is a rectangle!");

break;

default:

;;

}

}

}

User Jordan Messina
by
4.8k points