Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please answer in Java!! I am no sure how to ask the user if they would like to do it again. please help me with

Please answer in Java!!

I am no sure how to ask the user if they would like to do it again. please help me with this part. Also, I am not sure why I'm getting errors

image text in transcribedimage text in transcribedimport java.util.Scanner; public class ArrayMethods { //int [] arr; public static void main (String[] args) { int smallest,largest; Scanner option = new Scanner(System.in); System.out.println("1. Reverse an array"); System.out.println("2. Smallest element of an array"); System.out.println("3. Largest element of an array"); System.out.println("Enter your choice:"); int numberOption = option.nextInt(); Scanner number = new Scanner(System.in); System.out.println("Enter the number of elements:"); int total = number.nextInt(); int [] arr = new int[total]; for(int i=0;i

public static int [] smallestValue(int[] arr) { int smallest=arr[0]; for(int i=1;ilargest); { largest = arr[i]; } } return largest; } }

In your main method, display a menu to ask the user for their desired task. The options are listed below. Once the user chooses a task, ask them for their desired array size. Then, prompt them to fill the array with integer values. When displaying an array, all entries must be on the same line (see below for sample output). When the process is complete, ask the user if they want to do it again. public static int[] reverseArray (int[] arr) This method takes an integer array as a parameter and returns the array in reverse order. public static int smallestValue (int[] arr) This method takes an integer array as a parameter and returns the smallest value in the array. public static int largestValue (int[] arr) This method takes an integer array as a parameter and returns the largest value in the array. Example runs of the program: 1. Reverse an array 2. Smallest element of an array 3. Largest element of an array Enter your choice: 1 Enter the number of elements: 6 Enter element 0: -3 Enter element 1: 4 Enter element 2: 12 Enter element 3: 19 Enter element 4: -8 Enter element 5: 0 You entered: -3 4 12 19 -8 0 In reverse: 0 -8 19 12 4-3 Again? (1 for yes, 2 for no): 1 1. Reverse an array 2. Smallest element of an array 3. Largest element of an array Enter your choice: 2 Enter the number of elements: 6 Enter element 0: -3 Enter element 1: 4 Enter element 2: 12 Enter element 3: 19 Enter element 4: -8 Enter element 5: The smallest element is: -8 Again? (1 for yes, 2 for no): 2

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Data Analysis Using SQL And Excel

Authors: Gordon S Linoff

2nd Edition

111902143X, 9781119021438

More Books

Students also viewed these Databases questions