I'm new to java and I need help completing the question below. If anyone could help me with a simpler solution of this question. I tried to provide a working solution but I got stuck at number #10.
1.Create a new file called Rebel.java;
2.Create two arrays. One of them must store integer numbers and the other one must store words. Each of them must be able to store 5 values;
3.Fill the first array with numbers from 1 to 5 and the second one with numbers from 6 to 10; Note: The words array should contain the value in the form of a string and not the actual word i.e -> words[1] = "1";
4.Swap the numbers in the first array with the ones in the second one (swap numbers with the same index);
5.Multiply all the numbers in the first array by 4;
6.Multiply all the numbers in the second array by 3;
7.Print out the contents of both arrays.
8.Swap all the numbers in the first array with the ones in the second one but this time only swap the numbers at even positions.
9.For every number from 1 to 40 print out if it is in the array that stores numbers, the one that stores words or none of them.
10.For every number in the numbers array:
•Print it out;
•Print out the positions of the divisors it has in numbers array.
•Print out the positions of the divisors it has in words array.
11.Repeat #10 for the words array.
Here's my code:
public class Rebel
{
public static void main(String [] args)
{
int[] numbers = {1,2,3,4,5};
String[] words = {"6","7","8","9","10"};
numbers[0] = 6;
System.out.println("\nThe values in the numbers are:");
for(int x = 0; x<numbers.length;> {
numbers[x] = numbers[x] * 4;
System.out.println(" " + numbers[x]);
}
words[0] = "1";
System.out.println("\nThe values in the words are:");
for(int x = 0; x<words.length;> {
int wordsAsAnInt = Integer.parseInt(words[x]);
wordsAsAnInt = wordsAsAnInt * 3;
System.out.println(" " + wordsAsAnInt);
}
numbers[0] = 6;
words[0] = "1";
numbers[2] = 8;
words[2] = "3";
numbers[4] = 10;
words[4] = "5";
System.out.println("\nThe values in numbers from 1 to 40 are:");
for(int x = 0; x<numbers.length;> {
if(numbers[x] == 1 || numbers[x] < 40)
{
System.out.println(" " + numbers[x]);
}
}
System.out.println("\nThe values in the numbers are:");
for(int x = 0; x<numbers.length;> {
System.out.println(" " + numbers[x]);
}
}
}