Problem:- Write a program to obtain length (L) and breadth (B) of a rectangle and check whether its area is greater or perimeter is greater or both are equal.
Code:
import java.util.Scanner;
public class Main{
public static void main(String[] args) {
int l, b;
Scanner sc = new Scanner(System.in);
l = sc.nextInt();
b = sc.nextInt();
if(l*b > 2*(l+b)){
System.out.println("Area");
System.out.println(l*b);
}
if(l*b < 2*(l+b)){
System.out.println("Peri");
System.out.println(2*(l+b));
}
else{
System.out.println("Eq");
System.out.println(l*b);
sc.close();
}
}
}
Error showing:
Exception in thread "main" java.util.NoSuchElementException
at java.util.Scanner.throwFor(Scanner.java:862)
at java.util.Scanner.next(Scanner.java:1485)
at java.util.Scanner.nextInt(Scanner.java:2117)
at java.util.Scanner.nextInt(Scanner.java:2076)
at Main.main(Main.java:7)