07. Operations Between Numbers - Programming Basics -JAVA Test #5 (Incorrect answer)
Не мога да разбера защо и какво е грешно в решението ми на посочената. Judge ми дава 90% с грешка: Test #5 (Incorrect answer), но грешката не е показана.
Ето го и кода:
//----------------------------------------------------------------
import java.util.Scanner; public class NumberOps { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int n1 = Integer.parseInt(scanner.nextLine()); int n2 = Integer.parseInt(scanner.nextLine()); char sign = scanner.nextLine().charAt(0); int res; switch (sign) { case '+': res = n1 + n2; printDefMsg(n1, sign, n2, res, evenOdd(res)); break; case '-': res = n1 - n2; printDefMsg(n1, sign, n2, res, evenOdd(res)); break; case '*': res = n1 * n2; printDefMsg(n1, sign, n2, res, evenOdd(res)); break; case '/': if (n2 == 0){ printZeroMsg(n1); } else { Double nd1 = n1 * 1.0; Double res1 = nd1 / n2; System.out.printf("%d %c %d = %.2f", n1, sign, n2, res1); } break; case '%': if (n2 == 0){ printZeroMsg(n1); } else { res = n1 % n2; System.out.printf("%d %c %d = %d", n1, sign, n2, res); } break; default: break; } } private static String evenOdd(int number){ String evenOrOdd = "even"; if (number % 2 == 1){ evenOrOdd = "odd"; } return evenOrOdd; } private static void printZeroMsg(int n1){ System.out.printf("Cannot divide %d by zero ", n1); } private static void printDefMsg(int n1, char sign, int n2, int res, String evenOdd){ System.out.printf("%d %c %d = %d - %s", n1, sign, n2, res, evenOdd); } }
//---------------------------------------------------------------------------------
Ще се радвам ако някой може да ми помогне да го дебъгна.
условие линк:
https://softuni.bg/trainings/resources/officedocument/37449/exercise-problem-descriptions-programming-basics-with-java-january-2019/2211
задача 8