Write a program that reads four numbers from keyboard and displays to the screen the maximum of these numbers.

import java.io.*;

public class Solution { public static void main(String[] args) throws Exception { BufferedReader bf=new BufferedReader(new InputStreamReader(System.in)); int a=Integer.parseInt(bf.readLine()); int b=Integer.parseInt(bf.readLine()); int c=Integer.parseInt(bf.readLine()); int d=Integer.parseInt(bf.readLine());

  int largest=0;
  if(a>b)
  largest=a;
  if(b>a)
  largest=b;
  if(c>a)
  largest=c;
  if(d>a)
  largest=d;

        System.out.println(largest);

}

}

asked 15 May '16, 13:17

Saqib%20Shah's gravatar image

Saqib Shah
1
accept rate: 0%


 BufferedReader reader=new BufferedReader(new InputStreamReader(System.in));
    String number1=reader.readLine();
    String number2=reader.readLine();
    String number3=reader.readLine();
    String number4=reader.readLine();
    int num1=Integer.parseInt(number1);
    int num2=Integer.parseInt(number2);
    int num3=Integer.parseInt(number3);
    int num4=Integer.parseInt(number4);
    if (num1>=num2&&num1>=num3&&num1>=num4) {System.out.println(num1);}
    if (num2>=num1&&num2>=num3&&num2>=num4) {System.out.println(num2);}
    if (num3>=num1&&num3>=num2&&num3>=num4) {System.out.println(num3);}
    else {System.out.println(num4);}

whats wrong here?

link

answered 27 Mar, 09:38

TheHex's gravatar image

TheHex
1
accept rate: 0%

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "Title")
  • image?![alt text](/path/img.jpg "Title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Tags:

×4

Asked: 15 May '16, 13:17

Seen: 768 times

Last updated: 27 Mar, 09:38