could someone please point out what wrong with my code here? this is to find the maximum of 4
Use the keyboard to enter four numbers, and display the maximum of them. If the maximum occurs more than once, just display it once.
Requirements:
The program should read the numbers from the keyboard.
The program must display a number on the screen.
The program should display the maximum of four numbers.
If there are several maximum numbers, display any of them.
package com.codegym.task.task04.task0419;
/*
Maximum of four numbers
*/
import java.io.*;
public class Solution {
public static void main(String[] args) throws Exception {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
int a = Integer.parseInt(reader.readLine());
int b = Integer.parseInt(reader.readLine());
int c = Integer.parseInt(reader.readLine());
int d = Integer.parseInt(reader.readLine());
if (a>=b && a>=c && a>=d){
System.out.println(a);
}
if (b>=a && b>=c && b>=d){
System.out.println(b);
}
if (c>=a && c>=b && c>=d){
System.out.println(c);
}
if (d>=a && d>=b && d>=c){
System.out.println(d);
}
}
}
package com.codegym.task.task04.task0419;
/*
Maximum of four numbers
*/
import java.io.*;
public class Solution {
public static void main(String[] args) throws Exception {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
int a = Integer.parseInt(reader.readLine());
int b = Integer.parseInt(reader.readLine());
int c = Integer.parseInt(reader.readLine());
int d = Integer.parseInt(reader.readLine());
if (a>=b && a>=c && a>=d){
System.out.println(a);
}
if (b>=a && b>=c && b>=d){
System.out.println(b);
}
if (c>=a && c>=b && c>=d){
System.out.println(c);
}
if (d>=a && d>=b && d>=c){
System.out.println(d);
}
}
}