Java program Biggest Among 3 Numbers
The Java program finds a biggest number among 3 given numbers which are read by BufferedReader object wrapped of System.in (keyboard) object. While the Java program is running, Three inputs (data) read from keyboard as string object.The string inputs is converted into primitive integer datatype using a function, Integer.parseInt and stored these values into the variables.
Biggest among 3 numbers - Pseudocode
- Read three input integers
- Stored these on int variables A,B and C
- IF A > B and A > C , then print "A is Biggest"
- IF B>C , then print "B is Biggest"
- ELSE , print "C is Biggest"
Biggest among 3 numbers - Java Programming code
The Java program finds biggest number from given 3 numbers which are read from keyboard using BufferedReader object.
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class BiggestAmong {
public static void main(String[] args) throws IOException {
InputStreamReader dis =new InputStreamReader ( System.in );
BufferedReader br =new BufferedReader(dis);
System.out.println("Find a number biggest among 3 numbers n");
System.out.println("Enter value for A");
String tmp1 =br.readLine();
int a = Integer.parseInt(tmp1);
System.out.println("Enter value for B");
String tmp2 =br.readLine();
int b = Integer.parseInt(tmp2);
System.out.println("Enter value for C");
String tmp3 =br.readLine();
int c = Integer.parseInt(tmp3);
if ( a>b && a>c )
System.out.println("A is biggest : " + a);
else if ( b>c )
System.out.println("B is biggest : " + b);
else
System.out.println("C is biggest : " + c);
}
}
Java Program - Biggest among 3 numbers output
Find a number biggest among 3 numbers Enter value for A 67 Enter value for B 23 Enter value for C 45 A is biggest : 67
Comments
Post a Comment