122k views
1 vote
Largest of five (5 points). Write an algorithm that read 5 distinct integers and displays the largest value. Assume the input values are distinct integers. % java LargestOfFive 17 23 5 1 6 23 % java LargestOfFive 8 3 -8 4 1 8

User Matthewb
by
3.4k points

1 Answer

2 votes

Answer:

import java.io.*;

public class Larger {

public static void main(String[] args) throws IOException{

BufferedReader br=new BufferedReader(new InputStreamReader(System.in));// reading input from buffered reader

int a,max=-99999,i;

for(i=1;i<=5;i++)

{

a=Integer.parseInt(br.readLine());//converting string input string to int

if(a >max)

max=a;

}

System.out.println("Maximum value : "+max);

}

Step-by-step explanation:

User Victwise
by
3.6k points