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]
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);
}
}
}
}
}
Comments
Leave a comment