Arrays

Ads
 

Arrays

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

Hers'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; x++)
  {
     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; x++)
  {
     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; x++)
  {
     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; x++)
  {
     System.out.println(" " + numbers[x]);
  }

}

}

View Answers

Ads









Related Tutorials/Questions & Answers:
arrays
arrays  using arrays in methods   Java use arrays in methods import java.util.*; class ArrayExample{ public static int getMaxValue(int[] arr){ int maxValue = arr[0]; for(int i=1;i < arr.length;i
arrays
Store a table with students and information (name, ID, password, crypted password, etc) in a multi-dimensional array "stud"  Arrays and Strings: Store a table with students and information (name, ID, password, crypted password
Advertisements
Arrays
Arrays   Hi I need help with the following exercises. Exercise 1: Write a Java application in which the user is prompted for the total number of integer values to be stored in an array. Initialize the array with random values
Arrays
called Rebel.java; 2.Create two arrays. One of them must store integer numbers... the numbers in the second array by 3; 7.Print out the contents of both arrays. 8.Swap
Arrays in java
Arrays in java  what is param array in java
java arrays
java arrays  can i know how can we intilize the three dimentional arrays in java? and how can we assign thae values to that array
java arrays
java arrays  i need a java program to store student details like id,name,addr,marks,average,total..using arrays..input data using scanner class and by using class, object and constructor
Java with Arrays
Java with Arrays  I was given the assignment to create two parallel arrays; both of size 50 (declares 50 as a constant) One is an array of strings... and store it in the arrays. The input for the problem should be provided in a text
arrays
Arrays
Arrays
arrays
arrays
Arrays
arrays
arrays
arrays
Arrays
arrays
arrays
arrays
Compare two Byte Arrays?
Compare two Byte Arrays?  Compare two Byte Arrays
Comparing arrays not working correctly?
Comparing arrays not working correctly?  Comparing arrays not working correctly
ModuleNotFoundError: No module named 'Arrays'
ModuleNotFoundError: No module named 'Arrays'  Hi, My Python... 'Arrays' How to remove the ModuleNotFoundError: No module named 'Arrays'... to install padas library. You can install Arrays python with following command
What is javascript Arrays?
What is javascript Arrays?   Hi, I am learner of JavaScript. My question is that What is JavaScript Arrays ? How to Define the JavaScript arrays in you program. Please give an example show that i will try my self. Thanks
Are arrays primitive data types?
Are arrays primitive data types?   Hi, Are arrays primitive data types? thanks   Hi, In Java, Arrays are objects. Identifier are some simple variable names which is defined as the value container. The type of value
combine two arrays in php
combine two arrays in php  combine two arrays in php   $newArray = array_combine($diff, $pages_name['data']); foreach ($newArray as $data) { var_dump($data); exit('zzzzz'); echo $data . '<br>
Arrays in java 7
This tutorial describes the concept of Arrays in java 7
swap two integer arrays
swap two integer arrays  int [] array1 = {1,2,3,4,5} int [] array2 = {6,7,8,9,10} how can we swap the values of bith integer arrays results like this array1 = {6,7,8,9,10} array2 = {1,2,3,4,5
swap two integer arrays
swap two integer arrays  int [] array1 = {1,2,3,4,5} int [] array2 = {6,7,8,9,10} how can we swap the values of bith integer arrays results like this array1 = {6,7,8,9,10} array2 = {1,2,3,4,5
swap two integer arrays
swap two integer arrays  int [] array1 = {1,2,3,4,5} int [] array2 = {6,7,8,9,10} how can we swap the values of bith integer arrays results like this array1 = {6,7,8,9,10} array2 = {1,2,3,4,5

Ads