Example 3: Double Array: Write a Java program to update array elements at three different positions: start, middle, and end. Provide 3 different examples using user input for double arrays.
Java Programming Language Array in java (Article) Array in java (Program)
10Example 3: Double Array
Program:
import java.util.Scanner; public class UpdateDoubleArrayUser { public static void main(String[] args) { Scanner sc = new Scanner(System.in); double[] arr = {1.1, 2.2, 3.3, 4.4, 5.5, 6.6}; System.out.println("Original Array:"); for(double num : arr){ System.out.print(num + " "); } // User input to update start, middle, and end System.out.print("\nEnter new value for start: "); arr[0] = sc.nextDouble(); System.out.print("Enter new value for middle: "); arr[arr.length / 2] = sc.nextDouble(); System.out.print("Enter new value for end: "); arr[arr.length - 1] = sc.nextDouble(); System.out.println("Updated Array:"); for(double num : arr){ System.out.print(num + " "); } } }
Output:
This Particular section is dedicated to Programs only. If you want learn more about Java Programming Language. Then you can visit below links to get more depth on this subject.