Question: Problem Statement: Write a Java program that does the following: 1 . Creates an array of 1 0 0 integers. 2 . Initializes the array

Problem Statement:
Write a Java program that does the following:
1. Creates an array of 100 integers.
2. Initializes the array with a regular for loop to have values 1 to 100.
Meaning the first element has the value of 1 and the last element has the value of 100.
3. For each element in the array:
If the element is divisible by 2, replace it with its half (i.e., divide by 2).
If the element is divisible by 3, replace it with its triple (i.e., multiply by 3).
If the element is divisible by 5, replace it with its square (i.e., multiply it by itself).
If none of these conditions are met, leave the element unchanged.
If an element meets more than one of the above criterias (for example 6 is divisible by 2 and 3)
apply the first condition it meets (so in the case of 6, which is divisible by 2 and 3,
replace it with it's half, which is 3).
4. Print the original array, and then print the modified array after applying the above rules.
Requirements:
- You must use a 1D array of integers.
- The modulo/remainder operator (%) should be used to check divisibility conditions.
- Do not use any methods to solve this task; the entire logic should be written within the main method.
Sample Output:
Original Array:
[1,2,3,4,5,6,7,8,9,10,...,100]
Modified Array:
[1,1,9,2,25,3,7,4,27,5,...,50]

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!