Modify the program below, by adding an option 'f' to your menu program. If this option is chosen, the program should ask the user to enter 10 integers. The program should store each integer into an array (as each one is entered). Once the array contains the 10 integers, the program should output: - The sum of the 10 numbers entered - The average of the 10 numbers entered - The highest number entered - The lowest number entered import java.util.*; public class Code { static Scanner scan = new Scanner(System.in); public static int bigger(int x, int y, int z) { int large = x; if(x >= y && x >= z) large = x; else if(y>=x && y >=z) large = y; else large = z; return large; } public static int smaller(int x, int y, int z) { int small = x; if(x <= y && x <= z) small = x; else if(y<=x && y <=z) small = y; else small = z; return small; } public static void bigSmall() { System.out.print("Enter three numbers: "); int x = scan.nextInt(); int y = scan.nextInt(); int z = scan.nextInt(); System.out.println("Largest Number is " + bigger(x,y,z)); System.out.println("Smallest Number is " + smaller(x,y,z)); } public static void numList() { System.out.print("Enter two numbers: "); int m = scan.nextInt(); int n = scan.nextInt(); int count = 0; int sumOdd = 0; int i; for(i=m; i<=n; ++i) { System.out.print(i + " "); ++count; if(count==5) { System.out.println(); count = 0; } if(i%2 != 0) sumOdd = sumOdd + i; } System.out.println(); System.out.println("Sum of odd numbers between " + m + " and " + n + " is " + sumOdd); } public static void isTriangle() { System.out.print("Enter three sides of triangle: "); int a = scan.nextInt(); int b = scan.nextInt(); int c = scan.nextInt(); String res = ""; if(!((a+b) > c && (b+c) > a && (a+c) > b)) res = "not"; System.out.println("The three sides " + a + ", " + b + ", " + c + " can" + res + " form a triangle"); } public static void isPrime() { System.out.print("Enter a number: "); int n = scan.nextInt(); int i; boolean prime = true; if(n<2) prime = false; else { for(i=2; i<(n/2); ++i) { if(n%i == 0) { prime = false; break; } } } if(prime) System.out.println(n + " is a Prime number"); else System.out.println(n + " is not a Prime number"); } public static void main(String[] args) { System.out.print("Enter a character: "); char in = scan.next().toLowerCase().charAt(0); loop: while (in != 'q') { switch(in) { case 'a': System.out.println("Name"); System.out.println("Tutor's Name"); break; case 'b': bigSmall(); break; case 'c': numList(); break; case 'd': isTriangle(); break; case 'e': isPrime(); break; case 'q': break loop; default: System.out.println("Invalid Character. Please re-try OR type 'q' to exit"); break; } System.out.print("Enter a character: "); in = scan.next().toLowerCase().charAt(0); } } }
Modify the program below, by adding an option 'f' to your menu
program. If this option is chosen, the program should ask the user to enter 10
integers. The program should store each integer into an array (as each one is
entered). Once the array contains the 10 integers, the program should output:
- The sum of the 10 numbers entered
- The average of the 10 numbers entered
- The highest number entered
- The lowest number entered
import java.util.*;
public class Code {
static Scanner scan = new Scanner(System.in);
public static int bigger(int x, int y, int z) {
int large = x;
if(x >= y && x >= z)
large = x;
else if(y>=x && y >=z)
large = y;
else
large = z;
return large;
}
public static int smaller(int x, int y, int z) {
int small = x;
if(x <= y && x <= z)
small = x;
else if(y<=x && y <=z)
small = y;
else
small = z;
return small;
}
public static void bigSmall() {
System.out.print("Enter three numbers: ");
int x = scan.nextInt();
int y = scan.nextInt();
int z = scan.nextInt();
System.out.println("Largest Number is " + bigger(x,y,z));
System.out.println("Smallest Number is " + smaller(x,y,z));
}
public static void numList() {
System.out.print("Enter two numbers: ");
int m = scan.nextInt();
int n = scan.nextInt();
int count = 0;
int sumOdd = 0;
int i;
for(i=m; i<=n; ++i) {
System.out.print(i + " ");
++count;
if(count==5) {
System.out.println();
count = 0;
}
if(i%2 != 0)
sumOdd = sumOdd + i;
}
System.out.println();
System.out.println("Sum of odd numbers between " + m + " and " + n + " is " + sumOdd);
}
public static void isTriangle() {
System.out.print("Enter three sides of triangle: ");
int a = scan.nextInt();
int b = scan.nextInt();
int c = scan.nextInt();
String res = "";
if(!((a+b) > c && (b+c) > a && (a+c) > b))
res = "not";
System.out.println("The three sides " + a + ", " + b + ", " + c + " can" + res + " form a triangle");
}
public static void isPrime() {
System.out.print("Enter a number: ");
int n = scan.nextInt();
int i;
boolean prime = true;
if(n<2)
prime = false;
else {
for(i=2; i<(n/2); ++i) {
if(n%i == 0) {
prime = false;
break;
}
}
}
if(prime)
System.out.println(n + " is a Prime number");
else
System.out.println(n + " is not a Prime number");
}
public static void main(String[] args) {
System.out.print("Enter a character: ");
char in = scan.next().toLowerCase().charAt(0);
loop:
while (in != 'q') {
switch(in) {
case 'a':
System.out.println("Name");
System.out.println("Tutor's Name");
break;
case 'b':
bigSmall();
break;
case 'c':
numList();
break;
case 'd':
isTriangle();
break;
case 'e':
isPrime();
break;
case 'q':
break loop;
default:
System.out.println("Invalid Character. Please re-try OR type 'q' to exit");
break;
}
System.out.print("Enter a character: ");
in = scan.next().toLowerCase().charAt(0);
}
}
}
Trending now
This is a popular solution!
Step by step
Solved in 3 steps with 1 images