Computer Science, asked by sharanya1387, 11 months ago

Write a program to input 3 nos (positive/negative). If they are unequal display the greatest. Or else display they are equal. Also display whether the nos are all positive or all negative or mixed

Answers

Answered by sswaraj04
13

Answer:

import java.util.Scanner;

public class Demo {

  public static void main(String args[]) {

      Scanner sc=new Scanner(System.in);

      System.out.println("Enter first number : ");

      int a=sc.nextInt();

      System.out.println("Enter second number : ");

      int b=sc.nextInt();

      System.out.println("Enter third number : ");

      int c=sc.nextInt();

      if(a==b&&b==c)

      System.out.println("All are equal");

      else if(a>=b&&a>=c)

      System.out.println("Largest number is "+a);

      else if(b>=a&&b>=c)

      System.out.println("Largest number is "+b);

      else if(c>=a&&c>=b)

      System.out.println("Largest number is "+c);

      if(a>=0&&b>=0&&c>=0)

      System.out.println("All are positive numbers");

      else if(a<=0&&b<=0&&c<=0)

      System.out.println("All are negative numbers");

      else

      System.out.println("These are mixed(positive & negative)");

  }

}

Explanation:

Hope it helps :-)

Answered by shirisha1981
1

Answer:

import java.util.Scanner;

public class Demo {

public static void main(String args[]) {

Scanner sc=new Scanner(System.in);

System.out.println("Enter first number : ");

int a=sc.nextInt();

System.out.println("Enter second number : ");

int b=sc.nextInt();

System.out.println("Enter third number : ");

int c=sc.nextInt();

if(a==b&&b==c)

System.out.println("All are equal");

else if(a>=b&&a>=c)

System.out.println("Largest number is "+a);

else if(b>=a&&b>=c)

System.out.println("Largest number is "+b);

else if(c>=a&&c>=b)

System.out.println("Largest number is "+c);

if(a>=0&&b>=0&&c>=0)

System.out.println("All are positive numbers");

else if(a<=0&&b<=0&&c<=0)

System.out.println("All are negative numbers");

else

System.out.println("These are mixed(positive & negative)");

}

}

Similar questions