Scanner class
The Scanner class is a class in java.util, which allows the user to read values of various types. There are far more methods in class Scanner than you will need in this course. We only cover a small useful subset, ones that allow us to read in numeric values from either the keyboard or file without having to convert them from strings and determine if there are more values to be read.
// Scanner class work with JDK1.5 or above
import java.util.*;
class BiggestThree
{
public static void main(String args[])
{
int n1, n2, n3, big;
Scanner scan= new Scanner(System.in);
System.out.println("Please Enter No 1: ");
n1=scan.nextInt();
System.out.println("Please Enter No 2: ");
n2=scan.nextInt();
System.out.println("Please Enter No 3: ");
n3=scan.nextInt();
if(n1>n2 && n1>n3)
big=n1;
else if(n2>n1 && n2>n3)
big=n2;
else
big=n3;
System.out.println("Biggest No: " + big);
}
}
out put:
Please Enter No 1: 5
Please Enter No 2: 23
Please Enter No 3: 14
Biggest No: 23
No comments:
Post a Comment