Question

java: 1d arrays PLEASE NEED HELp THANK YOU!!! One dimensional (1D) array 1. Create an array...

java: 1d arrays

PLEASE NEED HELp THANK YOU!!!

One dimensional (1D) array

1. Create an array of 1000 integers. Name the array: x

2. Assign 95 to the ninth element, 25 to the twentieth element of array x.

3. Assign the sum of the ninth and the twentieth element to the sixtieth element of array x.

4. Display the sixtieth element of the array.

5. Use the for statement to generate all indexes to read and display all elements in array x.

6. Use the while statement to generate all indexes to read and display all elements in array x.

7. Create an application that stores the ages of all students in a class: 20 , 21 , 16 , 18 , 19 , 19 , 18 , 20 ,

19 , 18 , 19 , 18 , 19 , 21 , 22 , 26 , 31 , 35 , 22 , 26 , 17 , 17 , 19 , 18 , 16 , 19 , 18 , 14 , 26 , 31 , 21 , 20 ,

20 , 20 , 16 , 15 , 18 , 19 , 20 in an array. Name the array: age

8. Display the ages that are greater than 20. Use for or while structure to generate all indexes to read all elements in array age. Use if

structure to select the elements that are greater than 20.

9. Display the number of students who are younger than 18. Use for or while structure to generate all indexes to read all elements in array age. Use if structure to select the elements that are less than 20.

10. Display the average age. Use for or while structure to generate all indexes to read all elements in array age.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

1. Create an array of 1000 integers. Name the array: x

int x[]=new int[1000];

_____________

2. Assign 95 to the ninth element, 25 to the twentieth element of array x.

x[8]=95;

x[19]=25;

______________

3. Assign the sum of the ninth and the twentieth element to the sixtieth element of array x.

x[59]=x[8]+x[19];

______________

4. Display the sixtieth element of the array.

System.out.println("Sixtieth element of the array :"+x[59]);

______________

5. Use the for statement to generate all indexes to read and display all elements in array x.

for(int i=0;i<x.length;i++)

{

System.out.println(x[i]);

}

_______________

6. Use the while statement to generate all indexes to read and display all elements in array x

int i=0;

while(i<x.length)

{

System.out.println(x[i]);

}

________________

7. Create an application that stores the ages of all students in a class: 20 , 21 , 16 , 18 , 19 , 19 , 18 , 20 ,

19 , 18 , 19 , 18 , 19 , 21 , 22 , 26 , 31 , 35 , 22 , 26 , 17 , 17 , 19 , 18 , 16 , 19 , 18 , 14 , 26 , 31 , 21 , 20 ,

20 , 20 , 16 , 15 , 18 , 19 , 20 in an array. Name the array: age

Ans)

int age[]={20 , 21 , 16 , 18 , 19 , 19 , 18 , 20 ,19 , 18 , 19 , 18 , 19 , 21 , 22 , 26 , 31 , 35 , 22 , 26 , 17 , 17 , 19 , 18 , 16 , 19 , 18 , 14 , 26 , 31 , 21 , 20 ,20 , 20 , 16 , 15 , 18 , 19 , 20};

_________________

8. Display the ages that are greater than 20. Use for or while structure to generate all indexes to read all elements in array age. Use if

structure to select the elements that are greater than 20.

int i=0;

while(i<x.length)

{

if(age[i]>20)

{

System.out.println(age[i]);

}

}

___________________

9. Display the number of students who are younger than 18. Use for or while structure to generate all indexes to read all elements in array age. Use if structure to select the elements that are less than 20.

int count=0;

for(int i=0;i<x.length;i++)

{

if(age[i]<18)

{

count++;

}

}

System.out.println("No of students whose age is less than 18 are :"+count);

_______________

10. Display the average age. Use for or while structure to generate all indexes to read all elements in array age.

double sum=0;

for(int i=0;i<x.length;i++)

{

sum+=x[i];

}

System.out.println("Average age :"+(sum/x.length));

_____________Thank You

Add a comment
Know the answer?
Add Answer to:
java: 1d arrays PLEASE NEED HELp THANK YOU!!! One dimensional (1D) array 1. Create an array...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Please help with this C++ problem using Array Use a one-dimensional array to solve the following...

    Please help with this C++ problem using Array Use a one-dimensional array to solve the following problem. Read in 20 numbers, each of which is between 10 and 100. As each number is read validate it and store it in the array. After reading all the values, display only the unique values that the user entered. Make sure you account for the worst case scenario in which all 20 numbers are different. Use the smallest possible array to solve this...

  • need help with this python progam using numpy Create a 4x4 two dimensional array with numbers...

    need help with this python progam using numpy Create a 4x4 two dimensional array with numbers from 1 thru 16. show this then: Change the last element by dividing it in half. Show that the original array has changed. show this then: Set all values in row 2 to zero. Show the original array contains this change show this then: Set all values in column 1 to one. Shoe the original array contains this change. show this then: Display the...

  • This project will allow you to practice with one dimensional arrays, function and the same time...

    This project will allow you to practice with one dimensional arrays, function and the same time review the old material. You must submit it on Blackboard and also demonstrate a run to your instructor. General Description: The National Basketball Association (NBA) needs a program to calculate the wins-losses percentages of the teams. Write a complete C++ program including comments to do the following: Create the following: •a string array that holds the names of the teams •an integer array that...

  • Assembly Language Programming Assignment program must be in: MASM assembly language / x86 architecture / irvine...

    Assembly Language Programming Assignment program must be in: MASM assembly language / x86 architecture / irvine library procedures Objectives: 1. using register indirect addressing 2. passing parameters 3. generating “random” numbers 4. working with arrays Description: Write and test a MASM program to perform the following tasks: 1. Introduce the program. 2. Generate ARRAYSIZE random integers in the range [LO = 10 .. HI = 29], storing them in consecutive elements of an array. ARRAYSIZE should be set to 200....

  • Java Object Array With 2 Elements In 1 Object

    1. Create a UML diagram to help design the class described in Q2 below. Do this exercise before you attempt to code the solution. Think about what instance variables will be required to describe a Person class object; should they be private or public? Determine what class methods are required; should they be private or public?2. Write Java code for a Person class. A Person has a name of type String and an age of type integer.Supply two constructors: one will be...

  • Writing in a Java program, create an array with random numbers, find maximum, minimum, average, sort...

    Writing in a Java program, create an array with random numbers, find maximum, minimum, average, sort and find median, in that order. The array max size will have 20, however, each program run will be between 12 and 20 elements. Value of each element will be between 10 and 99. All project elements are integers. If possible, please use a data class. here's an example: ber of randon numbers: 16 ample Data: 7 69 46 74 21 14 70 10...

  • Pointer

    Please answer in C++Design and implement a program that stores the following numbers in an array named kilometers: 21, 23, 27, 18, 16, 22, and 19.The program should use a loop that displays the contents of the array.Next, create a pointer variable called kiloPointer and assign it the value of the address of the first element in the array. Use a loop that displays the array using pointer notation. The loop should display two columns of numbers, the value of the pointer and the...

  • Hello, In need of help with this Java pa homework. Thank you! 2. Create a normal...

    Hello, In need of help with this Java pa homework. Thank you! 2. Create a normal (POJo, JavaBean) class to represent, i. e. model, varieties of green beans (also known as string beans or snap beans). Following the steps shown in "Assignment: Tutorial on Creating Classes in IntelliJ", create the class in a file of its own in the same package as class Main. Name the class an appropriate name. The class must have (a) private field variables of appropriate...

  • C++ program; i need 7.14 as well please. 7.13 (Duplicate Elimination with arrayUse a one-dimensional array...

    C++ program; i need 7.14 as well please. 7.13 (Duplicate Elimination with arrayUse a one-dimensional array to solve the following problem. Read in 20 numbers, each of which is between 10 and 100, inclusive. As each number is read, validate it and store it in the array only if it isn't a duplicate of a number already read. After reading all the values, display only the unique values that the user entered. Provide for the "worst case" in which all...

  • ll this is a java code do it in eclipse please. thank you. Lab Objectives This...

    ll this is a java code do it in eclipse please. thank you. Lab Objectives This lab was designed to reinforce programming concepts from this lab, you will practice: • Declaring and initializing arrays. • Comparing input to array elements. • Preventing array out-of-bounds errors. The follow-up questions and activities will also give you practice: • Initializing array sizes during program execution. • Generalizing programs. Description Use a one-dimensional array to solve the following problem: Write an application that inputs...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT