Question
How do I modify the following java code? 1. Need to add 2 elements to the array 2.Need to modify it WITHOUT just changing the
How do I modify the following java code?
1. Need to add 2 elements to the array
2.Need to modify it WITHOUT just changing the input statement from "Enter five positive numbers...." to" Enter seven positive numbers.... "
3. And still have to call the modify method
4.ADD new print statement that says "The new array list of square roots are:"
import java.util.Scanner; public class DiscWeek7 { public static void modify (double values[]) { for (int i = 0; i < values.length; i++) { values[i] = (Math.sqrt(values[i])); } } public static void main(String[] args) { Scanner scan = new Scanner(System.in); double values[] = new double[5]; System.out.println("Enter five positive numbers separated by spaces to see their square roots."); for (int i = 0; i < values.length; i++) { values[i] = scan.nextDouble(); } modify(values); System.out.println("The square roots are:"); for (int i = 0; i < values.length; i++ ) { System.out.print(values[i] + " "); } scan.close(); } }
Step 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