I am submitting problems to the Judge system. While they are working perfectly in my IntelliJ IDE when I paste them in the Judge system and submit them - the system deems them wrong with exceptions.
public static void main(String[] args) {
Scanner user_input_width = new Scanner(System.in);
Scanner user_input_heigth = new Scanner(System.in);
String width;
String heigth;
System.out.println("Please enter width ");
width = user_input_width.next();
System.out.println(“Please enter height”);
heigth = user_input_heigth.next();
int x = Integer.parseInt(width);
int y = Integer.parseInt(heigth);
int area = x * y;
System.out.println(“The area of the rectangle is” + " " + area );
I think you can try and optimize your code a little:
public class Main{
public static void main(String[] args) {
Scanner user_input = new Scanner(System.in);
int width;
int height;
System.out.println("Please enter width: ");
width = user_input.nextInt();
System.out.println("Please enter height: ");
height = user_input.nextInt();
int area = width * height;
System.out.println("The area of the rectangle is " + area );
}
}
First, you can create just one Scanner. No need to make two of them. Then you can create width and height as int variable instead of String, and when the user types in, you can use nextInt() which will expect an int value. That way there is no need to convert the String to int.
What Ivan (koctech) suggested was not your problem but is more logical to use integers here nevertheless
1st error: The text messages was messing with Judge. --> the platform expect simple input and output as in the Task description. Be careful with Judge it is strict.
2nd error was the second scanner
3rd the code pasted here was with mixed quotation marks