Professional Documents
Culture Documents
methods
Students should be able to:
identify the prerequisites for data input
apply the correct method for the appropriate
data type
Input by using Scanner class.
Scanner Class allows the user to read values of various types
from the keyboard and other devices.
import java.util.*;
Or
import java.util.Scanner;
In order to make use of the Scanner class, it is
necessary to create an object as shown below:
(An object is a special type of variable
which will be discussed in Grade 10)
import java.util.Scanner;
class MATH {
public static void main()
{
Scanner sc = new Scanner(System.in);
System.out.print("Enter 2 numbers : ");
int n = sc.nextInt();
int m =sc.nextInt()
System.out.print(“You want to add or subtract …..enter + or - :");
char ch = sc.next().charAt(0);
if (ch == ‘+' )
System.out.println(“Sum :“ + (m+n));
else if (ch == ‘-’)
System.out.println(“Difference : “+ (m-n));
else
System.out.println("Invalid operator");
} }
Write a program that accepts the name and the
basic salary and calculates the allowances and
deductions as shown below.