Sunday, 5 November 2017

java full important program find max and min number



Problem 08:
Write a program that take five number from user and find maximum number from it.
Discripition:
Declared  max and min assign the value of first number to max and min compare with all this number.
Solution:
import java.util.*;
public class Message {
 public static void main(String[] args) {
  Scanner input= new Scanner(System.in);
   System.out.println("Enter five  number");
    int num=input.nextInt();
    int num1=input.nextInt();
    int num2=input.nextInt();
    int num3=input.nextInt();
    int num4=input.nextInt();
    int max,min;
    max=min=num;
    if(max<num1)
        max=num1;
    if(max<num2)
        max=num2;
    if(max<num3)
        max=num3;
    if(max<num4)
        max=num4;
    if(min>num1)
        min=num1;
    if(min>num2)
        min=num2;
    if(min>num3)
        min=num3;
    if(min>num4)
        min=num4;
    System.out.println("The maximum number is "+max);
    System.out.println("The minimum number is "+min);
 }}
Output:

No comments:

Post a Comment