Question: I need to Display a closing message before ending the application. So basically when the user presses the letter q it needs to say thanks
I need to Display a closing message before ending the application.
So basically when the user presses the letter "q" it needs to say "thanks for using this awesome program"
public static void main(String[] args) { // TODO Auto-generated method stub double[] arr=new double[5]; char ch='n'; Scanner s = new Scanner(System.in);
for(int i=0;i<5;i++) { System.out.print("Enter a decimal number: "); arr[i]=s.nextDouble();
} while(true) { System.out.println("Enter a to add"); System.out.println("Enter s to subtract"); System.out.println("Enter m to multiply"); System.out.println("Enter d to divide"); System.out.println("Enter q to quit"); String k=s.next(); ch = k.charAt(0); if(ch=='a') { double tot = 0; for(int i=0;i<5;i++) { tot += arr[i]; } System.out.println("The sum of all numbers is "+tot); } else if(ch=='s') { double tot = arr[0];
for(int i=1;i<5;i++) { tot -=arr[i]; } //double sum = first - tot; System.out.println("The difference of all the numbers is "+tot); } else if(ch=='m') { double tot = arr[0]; for(int i=1;i<5;i++) { tot *= arr[i]; } System.out.println("The product of all the numbers is "+tot); continue; } else if(ch=='d') { double tot = arr[0]; for(int i=1;i<5;i++) { tot /= arr[i]; } System.out.println("The quotient of all numbers is "+tot); continue; } else if(ch=='q') {
break; } else { System.out.println("You entered an invalid choice. Please try again."); continue; } } } }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
