1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
larisa86 [58]
3 years ago
5

1D Array Assignment Outcome: Student will demonstrate the ability to use a one-dimensional array. Student will demonstrate the a

bility to sort and search arrays. Student will demonstrate the ability to use methods. Program Specifications: Write a program that does the following: Create an array of 100 integers. Store 100 random integers (between 1 and 100) in the array. Print out the elements of the array. Sort the array in ascending order. Print out the sorted array. Prompt the user to enter a number between 1 and 100. Search the array for that number and then display "Found" or "Not Found" message. Display each number from 1 to 100 and the number of times each is found in the array. Display the average of the numbers in the array. Display the highest number in the array. Display the lowest number in the array. Other requirements. Everything should be done using METHODS. NO NEED FOR A MENU SYSTEM. Just call the methods in the sequence above. Add your design tool to your project.

Computers and Technology
1 answer:
sukhopar [10]3 years ago
7 0

Answer:

Program to this question as follows:

program:

import java.util.*; //import package for user input

public class Main  //defining class  

{

public static void main(String[] as)//defining main function

{//defining integer array

int [] num = new int[113];  

boolean find_in = false; //defining boolean variable

int [] counts = new int[101];//defining integer array

int y, tem = 0, counter = 0,in=0,x,find; //defining integer variable

Scanner ox= new Scanner(System.in); //creating Scanner class Object

while(counter <= 112) //loop to check condition

{

num[counter++] = generateRandomNumber(); //using array to hold random function value.  

}

System.out.println("The array:"); //message

for(x = 0; x < 112; x++) // loop to count the value

{

if(x != 0 && x % 9 == 0) // if block to chek value

System.out.println(); // print  

else

System.out.print(num[x] + " "); // print array

}

// sort in ascending order

Arrays.sort(num); //using sort method

System.out.print("\n\nThe array in sorted order:"); // print value

for( x = 0; x < num.length; x++) // loop uses if block to check value is divisiable by 9  

{

if(x % 9 == 0) //check condition  

System.out.println(); // print  

else

System.out.print(num[x] + " "); // print array

}

// search for a number

System.out.print("\n\nEnter a number to search: "); // print message

find= ox.nextInt(); // input number by user

for(x= 0;x< num.length;x++) //loop to count values

{

if(num[x] == find) //check value

{

find_in = true; //change value

in= x;

break; //using break keyword

}

}

if(find_in)  //find value

System.out.println(find + " is found at index " + in); // print location

else

System.out.println("Not found"); //message

// display count of each numbers

System.out.println("Count of each numbers:"); //message

for(y = 1; y< num.length; y++) // loop to store element in counts array  

{

tem = num[y]; //hold value

counts[tem]++; //increment value

}

for(x = 1; x< counts.length; x++) //loop to print value

{

System.out.println(x + ": " + counts[x]); // print value

}

// average of the numbers in the array

for(x = 0; x < num.length; x++) // loop to calculate sum and average

{

sum += num[x]; //calculate sum

}

avg = (sum / 100); // calculate avg

System.out.println("\nThe average of the numbers in the array: " + avg);

// highest number in the array

int high= num[0]; //find number

for(x= 0;x < num.length;x++)

{

if(num[x] > high)

high = num[x]; //hold value of highest Number

}

System.out.println("\nThe highest number is: " + high); //print value

int low = num[0]; // defining variable for lowest number

for(x= 0; x < num.length - 1; x++) // loop to calculate lowest number

{

if(num[x] < low) //condition for lowest number

low = num[x]; //hold lowest number

}

System.out.println("\nThe lowest number is: " + low); //print value

}

public static int generateRandomNumber() //defining function  

{

Random ra = new Random(); //creating Random function Object

return (ra.nextInt(100)+ 1); //input and return value

}

}

Output:

the output of the given code is display in image

Explanation:

In the above program, an array is declared that uses a random function to input the number, in the next step the sort function is used, that sorted all array elements, in the next step the scanner class is used, that input the number form the user ends and pass search in the sorted array.

  • After searching the average of array elements is calculated. In this array we calculate the highest and lowest number of the array to print all the values the print method is used.
  • At the last, the rand method is used that generates the random number for the array and passes into a num array that prints the values.

You might be interested in
What is one advantage of using object-oriented programming?
maxonik [38]
That answer would be B hope it helps
6 0
3 years ago
Read 2 more answers
What does the windows update feature allow you to do?
Mariulka [41]
The answer is D
Explanation: none
3 0
3 years ago
Read 2 more answers
Match the part of the browser window to the correct description.
hodyreva [135]

Answer:

1. Tabs: allows you to drag the window to a new location

Explanation: Tab is the key that is used to switch between different windows or websites that are opened at a time. This can be done by pressing Ctrl+Tab

2. Status Bar: displays whether the Web page is secure or not

Explanation: Status bar is used to show the status or information related to that page. Like Information related safety precaution.

3. Title Bar: allows you to quickly move between different Web sites

Explanation: Title bar consist of the name of different websites that are open at particular time. This shows at the top of the browser. We can quickly move on different websites using title of website.

4. Bookmarks: save Web addresses so you can return to them quickly

Explanation: Bookmarks are the pages that we save in bookmark menu, to re-open the page whenever its needed.

4 0
3 years ago
How would a static local variable be useful?
Lelechka [254]

Answer: Static local variable is a variable that is initialized as static only one time inside a function and whenever it is called in that function it will be accessible.

Explanation: Static local variables are very useful variables which are declared as static in a particular function. Static local variable is initialized only one time in a function and whenever the function in which it has been declared ,the value of the variable will be accessible by as many times it has been called in the function in which it is declared.

8 0
3 years ago
What is an algorithm?A. a series of actions that solve a particular problem.B. an English description of a problem to be solved.
Elena L [17]

Answer:

A. a series of actions that solve a particular problem.

Explanation:

An algorithm refers to step by step instructions used to fix a problem and they are used for tasks like make calculations and process data. Algorithms are important for computers to be able to process information as they provide the instructions on how a task has to be performed. According to this, an algorithm is a a series of actions that solve a particular problem.

4 0
3 years ago
Other questions:
  • A blood bank maintains two tables - DONOR, with information about people who are willing to donate blood and ACCEPTOR, with info
    10·1 answer
  • Liz will use a CD-R compact disk to write to more than once. Carlo will use a CD-RW compact disk to write to more than once. Who
    8·2 answers
  • Your computer has gradually slowed down. What's the most likely reason?
    8·1 answer
  • The mutt software is an example of what type of mail service software on Linux? a. Mail Delivery Agent b. Mail Transport Agent c
    5·1 answer
  • What is an IP address and where I can find the IP address for my computer?
    14·1 answer
  • The method main of a class is called when you instantiate an object of that class like this: Box myBox = new Box();
    9·1 answer
  • Implement a Python function with the signature Transfer(S, T) that transfers all elements from the ArrayStack instance S onto th
    13·1 answer
  • Describe the process of normalization and why it is needed.
    12·1 answer
  • A program that will read each player’s name and golf score as keyboard input,
    9·1 answer
  • Java Programming Using nested if statement For a student to be accepted in XYZ College, the student must meet the following requ
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!