22. Area of Figures проблем, Judge ми дава 75\100 не мога да разбера защо.
Това е задачата:
Problem: 22 Area of Figures
▪ Write a program to calculate figure area, which:
▪ Reads the type of the figure (String)
▪ Reads the size of the figure (one or two int values)
▪ Checks if the figure is square, rectangle or circle
▪ Prints the calculated area, formatted to the 2nd decimal
square
5
25.00
Това ми е кода
import java.util.Scanner;
public class areaOfFigures1 {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
String type = scanner.nextLine();
double area = 0;
if (type.equals("square")) {
double size = scanner.nextDouble();
area = size * size;
}
else if (type.equals("rectangel")) {
double size1 = scanner.nextDouble();
double size2 = scanner.nextDouble();
area = size1 * size2;
}
else if (type.equals("circle")) {
double radius = scanner.nextDouble();
area = radius * radius * Math.PI;
}
System.out.printf("%.02f\n", area);
}
}
В IntelliJ Idea всичко е наред, но в Judge дава друг резултат.
Пробвах и с Double.parseDouble(scanner.nextLine()); вместо
scanner.nextDouble();.
Ако някой може да хвърли свелина върху проблема, ще съм много благодарен.
Благодаря.
Благодаря много !!! :)