Computer Science, asked by AhaanaAS, 18 days ago

write this in java (blueJ)
no spam

Attachments:

Answers

Answered by anindyaadhikari13
1

Solution 1:

public class Greatest{

   public static void main(int a, int b, int c){

       int max=Math.max(a,Math.max(b,c));

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

   }

}

Logic is very simple. Accept three numbers. Compare the first number with the maximum of second and third number using max() function to get the highest value.

Solution 2:

import java.util.Scanner;

public class Grade{

   public static void main(String s[]){

       Scanner sc=new Scanner(System.in);

       System.out.print("Enter your marks: ");

       double marks=sc.nextDouble();

       sc.close();

       if(marks<0 || marks>100)

           System.out.println("Invalid Marks.");

       else{

           if(marks>=80)

               System.out.println("Grade: A");

           else if(marks>=50)

               System.out.println("Grade: B");

           else

               System.out.println("Grade: C");

       }

   }

}

Check the conditions given using if else statements. If conditions become true, display the respective grade.

Solution 3:

import java.util.Scanner;

public class Calculator{

   public static void main(String s[]){

       int a,b,result;

       Scanner sc=new Scanner(System.in);

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

       a=sc.nextInt();

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

       b=sc.nextInt();  

       System.out.println("\n1. Addition.");

       System.out.println("2. Subtraction.");

       System.out.println("3. Multiplication.");

       System.out.println("4. Division.");

       System.out.println("5. Modulo Operation.");

       System.out.print("\nEnter your choice: ");

       switch(sc.nextInt()){

           case 1:

               result=a+b;

               System.out.println("Sum = "+result);

               break;

           case 2:

               result=a-b;

               System.out.println("Difference = "+result);

               break;

           case 3:

               result=a*b;

               System.out.println("Product = "+result);

               break;

           case 4:

               result=a/b;

               System.out.println("Quotient = "+result);

               break;

           case 5:

               result=a%b;

               System.out.println("Remainder = "+result);

               break;

           default:

               System.out.println("Invalid Choice.");

       }

       sc.close();

   }

}

Accept two numbers, request the user to enter a valid number and perform the respective operator from the list of choices using switch-case statement.

Refer to the attachments for output.

Attachments:
Similar questions