0

Hi need help again. It is for school purposes. WHAT IS WRONG IN THIS CODE? :(

import java.util.Scanner; public class Javaexcercise { public static void main(String[] args) { Scanner in = new Scanner(System.in); System.out.print("Input 1st number: "); int num1 = in.nextInt(); System.out.print("Input 2nd number: "); int num2 = in.nextInt(); System.out.println("Addition of two numbers: " + num1 + " + " + num2 + " = " + (num1 + num2)); System.out.println("subtraction of two numbers: " +num1 + " - " + num2 + " = " + (num1 - num2)); System.out.println("Multiplication of two numbers: "+ num1 + " x " + num2 + " = " + (num1 * num2)); System.out.println("Division of two numbers: " + num1 + " / " + num2 + " = " + (num1 / num2)); System.out.println("Remainder of two numbers: "+ num1 + " mod " + num2 + " = " + (num1 % num2)); } }

9th Apr 2021, 11:38 AM
Janiera Raniola
Janiera Raniola - avatar
4 Respostas
+ 5
code is correct and working but take care of division by 0, also it will do integer division only. https://www.geeksforgeeks.org/java-program-to-handle-divide-by-zero-and-multiple-exceptions/
9th Apr 2021, 11:46 AM
Gaurav Agrawal
Gaurav Agrawal - avatar
+ 1
I see another with the same exercise. I have done It so... Also nextInt can trows an exception and fail if input is not formatted correctly https://code.sololearn.com/c8a18A8A223A/?ref=app
9th Apr 2021, 3:02 PM
Ciro Pellegrino
Ciro Pellegrino - avatar
0
Gaurav Agrawal thank you
10th Apr 2021, 12:37 AM
Janiera Raniola
Janiera Raniola - avatar
0
Ciro Pellegrino thank you
10th Apr 2021, 12:37 AM
Janiera Raniola
Janiera Raniola - avatar