Question
For the code below, get rid of all the while loops and instead use recursion, no loops. import java.io.Console; import java.util.Scanner; public class Homework5 {
For the code below, get rid of all the while loops and instead use recursion, no loops.
import java.io.Console;
import java.util.Scanner;
public class Homework5 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("Enter a number from 1-5: ");
int number = sc.nextInt();
// input validation
while(number 5){
System.out.print("Enter a number from 1-5: ");
number = sc.nextInt();
}
while(number > 0){
number = number - 1;
System.out.println("Enter list of integers (0 to stop): ");
System.out.print("Enter input: ");
int input = sc.nextInt();
if(input == 0){
System.out.println("ERROR: At least one number should be greater than 0");
}else
{
int min = input;
int max = input;
while(true){
System.out.print("Enter input: ");
input = sc.nextInt();
if(input == 0)
break;
if(input > max)
max = input;
if(input
min = input;
}
System.out.println("Max: "+max);
System.out.println("Min: "+min);
System.out.println();
}
}
}
}
1. Prompt for and read a number between 1 and 5. Repeat this step until the input is 1. 5. 2. Repeat the following multiple times according to the number read in step 1. a. Read in a list of integers en with a 0. The 0 marks the end of the input and is not ding considered part of the list b. Print the largest and smallest integers in the list c. If only a zero appears in the list, print an error message Here is a pseudo-code solution. begin repeat prompt user to enter a number from 1 to 5 read number until number is from 1 to 5 repeat number times decrement number read input if input print error message else set min to input set max to input read input repeat while input is not-0 if input min then set min to input else if input max then set max to input end if end if read input end repeat print max print min end if end repeat end For this assignment, you are to convert the algorithm into a non-iterative solution (no loops) and code it in Java following the coding style requirements posted for the class. You may design your solution toStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started