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
Related Tutorials/Questions & Answers:
arraysarrays 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
arraysStore 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
java arraysjava 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 arraysjava 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 ArraysJava 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
java arraysjava arrays how do you write the code for multipliying 2 double
arrays to be in a 3rd double array?
here is my code:
package employeepay;
/**
*
* @author Owner
*/
public class Main
{ADS_TO_REPLACE_1
/**
* @param args
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
arrays in java - Java Beginnersarrays in java Hi All,
I have two
arrays. in this two array some name are same. I want to merge those
arrays into single. But while merging I want to delete duplicate entries. How merge those
arrays.
Thanks,
mln15584
java; arrays - Java Beginnersjava
arrays example How can you create a program, by using
arrays and the output would be X. by using char or string.Thank you
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 phpcombine 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>
swap two integer arraysswap 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 arraysswap 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
reverse arrays in javareverse
arrays in java how do i make a code that can be used to reverse the elements of an array in two dimension such that the last element of an array becomes the first element of the array and the first element of an array
reverse arrays in javareverse
arrays in java how do i write a program in array of size n*m where both n and m are greater than 20 such that the 1st element of an array becomes the last and vice verse
swap two integer arraysswap 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
intersection of two java arraysintersection of two java arrays I am trying to figure out how to compare two
arrays and get the intersection and put this into a third array of the correct size. I know how to copy the two
arrays into the third array but am
Java Arrays TutorialsThe java.util.Arrays class helps the programmers to manipulating the
arrays. It provides the methods to easily manipulate the
arrays. Methods provided...(). Browse the following code to Learn Java
Arrays in detail
Arrays in javaArrays in java
Arrays are the data structure of java , we use array
where we need contiguous memory allocation. Array stores same type of data
structure. Array type is checked at compile time. An array has a fixed length.
Declaration
Variable length arrays?Variable length
arrays? Hi:
I enjoy reading from your site especially the example seem to speak louder than the description. Thanks for your... of
arrays or if there is a smart way to handle this.
Thanks for your help.
Varma
Introduction to java arrays Introduction to java
arrays
...
of
Arrays in Java Programming language. You will learn how the Array class...
arrays. To meet this feature java
has provided an Array class which abstracts
Printing 2 arraysPrinting 2 arrays Hi,
I have 2
arrays:
String [] head = {"Name", "Date of birth", "PPS number"};
String [] personal= {value1, value2, value3};
I want this 2
arrays to be printed out in the following manner:
head[0] tab
Comparing Arrays
Comparing
Arrays : Java Util
This section show you how to determine the given
arrays
are same or not. The given program illustrates you how to compare
arrays
according
Associative ArraysAssociative
Arrays
In this section, you will learn about associative
arrays and it 's
implementation.
In an associative array, a key is associated with a value. We can use
values as key and assign value to them.
Given below