write a program to input two numbers and print the highest using buffer reader
Answers
Answer:
Program:-
//Program using Buffered Reader
import java.io.*;
public class Main
{
public static void main(String args[])throws IOException
{
BufferedReader in=new BufferedReader(new InputStreamReader(System.in));
int a,b;
System.out.println("Enter the numbers");
a=Integer.parseInt(in.readLine());
b=Integer.parseInt(in.readLine());
System.out.println("The greater number="+Math.max(a,b));
}
}
- The first photo is the program
- The second photo is the output
Note:In place of Math.max you may use if and else statement just use this:
import java.io.*;
public class Main
{
public static void main(String args[])throws IOException
{
BufferedReader in=new BufferedReader(new InputStreamReader(System.in));
int a,b;
System.out.println("Enter the numbers");
a=Integer.parseInt(in.readLine());
b=Integer.parseInt(in.readLine());
if(a>b)
{
System.out.println("The greater number="+a);
}
else
{
System.out.println("The greater number="+b);
}
}
}
![](https://hi-static.z-dn.net/files/dba/acabc449dab4aabb326476182a4a0b39.jpg)
![](https://hi-static.z-dn.net/files/d6b/431666e225cb1b0232ddefbdc2aad2f7.jpg)