Answer to Question #174214 in Java | JSP | JSF for Jean Claude

Question #174214

Write a java program that reads three (3) int variables and performs the below operations: i. Prints out their product ii. Prints out the maximum of the numbers Do not use any inbuilt Java Methods to return the maximum. Extra marks will be awarded for clarity of code and comments. [8 marks]


B. Algorithms perform differently on different data sets and as such we may be interested in either their Best-case, Worst-case or Average-case scenarios. Explain why the Worst-case for an insertion sort is with reverse-sorted data. [6 marks] 


1
Expert's answer
2021-03-22T13:08:38-0400
import java.util.Scanner;

public class IoProjects {
    
    
    public static void main(String[] args) {
        // TODO Auto-generated method stub
//number scanner
        Scanner sc=new Scanner(System.in);
        
        //scan first number
        System.out.println("Enter the integer ");
        int num1=sc.nextInt();
        System.out.println("First scanned number is: "+num1);
        
        //scan 2nd number
        System.out.println("Enter the 2nd integer ");
        int num2=sc.nextInt();
        System.out.println("Second scanned number is: "+num2);
        
        // scan 3rd number
        System.out.println("Enter the 3rd integer ");
        int num3=sc.nextInt();
        System.out.println("Third scanned number is: "+num3);

        // product of the three scanned number
        System.out.println();
        int product;
        product=num1*num2*num3;
        System.out.println("The product of the three scanned number is: "+product);
        
        System.out.println();
        
        //find maximum and minimum number
        int d1,d2,d3;
        d1 =num1-num2;
        d2=num2-num3;
        d3=num1-num3;
        if(d1>0){
            if(d3>0){
                System.out.println(num1+" is maximum than "+num2+" and "+num3);
            }else{
                System.out.println(num3+" is maximum than "+num1+" and "+num2);
            }
        }else{
            if(d2>0){
                System.out.println(+num2+" is maximum ");
            }else{
                if(d3>0){
                    System.out.println(num1+" is maximum than "+num2+" and "+num3);
                }else{
                    System.out.println(num3+" is maximum than "+num1+" and "+num2);
                }
                
            }
            
        }
        
    }

}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog