Page 135 - CA_Blue( J )_Class9
P. 135
Output: If b is 0, then "Cannot divide by 0" message will appear, else it will give the correct result of the division.
Program 2 Write a program to take three values from the user and display their total.
1 import java.util.*;
2 class userinput
3 {
4 public static void main(String[] args)
5 {
6 Scanner sc= new Scanner(System.in); //System.in is a standard input
stream
7 System.out.print("Enter first number- ");
8 int a= sc.nextInt();
9 System.out.print("Enter second number- ");
10 int b= sc.nextInt();
11 System.out.print("Enter third number- ");
12 int c= sc.nextInt();
13 int d=a+b+c;
14 System.out.println("The total of the numbers is: " +d);
15 }
16 }
You will get the following output:
Input in Java 133

