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
Romashka [77]
3 years ago
11

Create a new Java project/class called ChangeUp. Create an empty int array of size 6. Create a method called populateArray that

will pass an array, use random class to choose a random index and prompt the user to enter a value, store the value in the array. Note: Generate 6 random index numbers in an attempt to fill the array. Create a method called printArray that prints the contents of the array using the for each enhanced loop. Submit code. Note: It is possible that your array won't be filled and some values will still have 0 stored. That is acceptable.
Computers and Technology
1 answer:
-Dominant- [34]3 years ago
3 0
<h2>Answer:</h2><h2></h2>

//import the Random and Scanner classes

import java.util.Random;

import java.util.Scanner;

//Begin class definition

public class ChangeUp {

   

   //Begin the main method

  public static void main(String args[]) {

       //Initialize the empty array of 6 elements

      int [] numbers = new int [6];

       

       //Call to the populateArray method

       populateArray(numbers);

       

       

   } //End of main method

   

   

   //Method to populate the array and print out the populated array

   //Parameter arr is the array to be populated

   public static void populateArray(int [] arr){

       

       //Create object of the Random class to generate the random index

       Random rand = new Random();

       

       //Create object of the Scanner class to read user's inputs

       Scanner input = new Scanner(System.in);

       

       //Initialize a counter variable to control the while loop

       int i = 0;

       

       //Begin the while loop. This loop runs as many times as the number of elements in the array - 6 in this case.

       while(i < arr.length){

           

           //generate random number using the Random object (rand) created above, and store in an int variable (randomNumber)

           int randomNumber = rand.nextInt(6);

       

           //(Optional) Print out a line for formatting purposes

           System.out.println();

           

           //prompt user to enter a value

           System.out.println("Enter a value " + (i + 1));

           

           //Receive the user input using the Scanner object(input) created earlier.

           //Store input in an int variable (inputNumber)

           int inputNumber = input.nextInt();

           

           

           //Store the value entered by the user in the array at the index specified by the random number

           arr[randomNumber] = inputNumber;

           

           

           //increment the counter by 1

          i++;

           

       }

       

       

       //(Optional) Print out a line for formatting purposes

       System.out.println();

       

       //(Optional) Print out a description text

      System.out.println("The populated array is : ");

       

       //Print out the array content using enhanced for loop

       //separating each element by a space

       for(int x: arr){

           System.out.print(x + " ");

       }

   

       

  } //End of populateArray method

   

   

   

} //End of class definition

<h2>Explanation:</h2>

The code above is written in Java. It contains comments explaining the lines of the code.

This source code together with a sample output has been attached to this response.

Download java
<span class="sg-text sg-text--link sg-text--bold sg-text--link-disabled sg-text--blue-dark"> java </span>
0d7446bcb6b48f78b8adbfa3da89789c.png
You might be interested in
Account numbers sometimes contain a check digit that is the result of a mathematical calculation. The inclusion of the digit in
marishachu [46]

Answer:

using System;

class CheckDigit

{

public static void Main (string[] args)

{ //Accepting value from user

Console.WriteLine ("Enter a four-digit account number");

int acc = Convert.ToInt32(Console.ReadLine());

int d=acc%10; //extracting the last digit

acc=acc/10; //having the first three digit

if(acc % 7 == d) //checking and displaying

Console.WriteLine ("Valid Account Number");

else

Console.WriteLine ("Invalid Account Number");

}

}

Explanation:

3 0
3 years ago
Does anyone else realize how the only tutor is for math never any other subjects?​
Slav-nsk [51]

Answer:

yes I do and I wonder why ??

7 0
3 years ago
Words like "free" or "percent off" will not only trigger spam filters for your email, but will also ___________
weeeeeb [17]

Answer:

eliminasnados

Explanation:

6 0
3 years ago
How do I write a program in Pascal that finds the index of the minimum number of an array(using Function) and replaces it to a n
nordsb [41]

Answer:

program arraysminfinder;

procedure minreplace();

var

no: array [1..10] of integer;  (*no is an array of integers, 10 in all *)

a: integer= 0;

i: integer= 0;

c: integer= 0;

k: integer=0;

N: integer=0;

begin

(* We need to first initialize the array no with 0 values *)

for a := 1 to 10 do

no[a]:=0;

c:=no[1];

for a := 1 to 10 do

begin

  if (no[i]<c) then

  begin

   c:=no[i];

   k:=i;

  end

  else

  begin

      i:=i+1;

  end

 end;

  writeln('Enter the new number:');

  read(N);

  no[k]:=N;

  for a := 1 to 10 do

  begin

     writeln('The array elements are:',no[a]);

   end;

end;

begin

end.

Explanation:

The program is as above.  I have used a function, a for loop, an array of integers, and the if then else ladder for getting the desired output as mentioned in the program. If in case you want procedure for input and output, create a procedure like:

procedure replacenum():integer;

Begin

 writeln("Enter the new number:" N);

    no[k]:=N;

   for a := 1 to 10 do

         writeln("The array elements are:"no[a]);

 end.

Similarly you can make a procedure for input.

5 0
4 years ago
Is it ok to use a does red wine clean the inside of a computer true or false
Dmitry [639]
I don't understand what you are saying but I'm willing to help
4 0
3 years ago
Read 2 more answers
Other questions:
  • Assume the existence of a Building class with a constructor that accepts two parameters:_________ a reference to an Address obje
    5·1 answer
  • When the word “computer” was coined, what did it mean?
    12·1 answer
  • What does the word tolerance mean in textiles?
    9·1 answer
  • Derek has an interest in designing video games. What requirements should he fulfill to be a game designer? To be a game designer
    10·1 answer
  • Why are hardline Ethernet connections always faster than WiFi?
    8·1 answer
  • How many pieces are there in a normal laptop??? Good luck and solve carefully
    9·1 answer
  • Number the steps to describe how Tristan can complete
    6·2 answers
  • The following Mic1 microcode excerpt shows support for a possible 7 bit opcode, 8 bit integer argument machine instruction (orga
    14·1 answer
  • What does GUI stands for and what is it function?​
    5·2 answers
  • A(n) __________ structure is a structure that causes a statement or a set of statements to execute repeatedly.
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!