Question

In Java create an integer array named dice1 with a size of 10. Populate each array...

In Java create an integer array named dice1 with a size of 10. Populate each array location with a roll of a six-sided die (hint: an int value of 1 through 6). Print the array out using an enhanced for loop.

Sample output:

Question 1
dice1 = 1 1 6 2 3 5 1 5 4 5

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

If you have any queries write a comment. If understood upvote Thanky you.

SOLUTION:

import java.util.Random;
public class Main
{
   public static void main(String[] args) {
       int dice1[]=new int[10];
       //array to store dice values
       Random rand = new Random(); //random number generation instance
       for(int i=0;i<10;i++){//loop to store data of dice with random number
       dice1[i]=rand.nextInt(6)+1;
       //here i am generating random number from 0 to 5 and then adding 1
       //to get random number from 1 to 6
       }//print the dice values
       System.out.print("dice1 = ");
       for(int i=0;i<10;i++){
       System.out.print(dice1[i]+" ");
       }
   }
}

CODE IMAGE:

ava import java.util.Random; public class Main public static void main(String[] args) { int dice1[]=new int[10]; //array to s

Add a comment
Know the answer?
Add Answer to:
In Java create an integer array named dice1 with a size of 10. Populate each 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
  • Create three variables for an int array, the size of the array, and a Scanner object...

    Create three variables for an int array, the size of the array, and a Scanner object to read keyboard input. Ask the user to specify the size of the array and then construct an int array of that size. Next, use a for loop to continuously ask the user to specify values for each location in the array. Lastly, print contents of the array as a histogram using the asterisk character (*). This will require using nested for loops. The...

  • Java arrays Create method named repeatedN that takes two integer parameters named range and n and...

    Java arrays Create method named repeatedN that takes two integer parameters named range and n and returns an integer array Method should return an integer array that has numbers 0 - range repeated in order n times If range is less than or equal to 0; return an array that has 0 repeated n times Create a second method named printArray that takes an integer array as a parameter. The method should print out every element on the same line...

  • In Java: Create an array of Integers with 10 elements, loop (use a for loop) through...

    In Java: Create an array of Integers with 10 elements, loop (use a for loop) through the array of integers printing their values to the screen. Create an array of Strings with 10 elements, loop (use a for loop) through the array of Strings printing their values to the screen. Finally, create an ArrayList of Integers. Use the loop from part 1 above and add each integer as you print it to the ArrayList as well, then start a final...

  • (+30) Provide a python program which will Populate an array(list) of size 25 with integers in...

    (+30) Provide a python program which will Populate an array(list) of size 25 with integers in the range -100 (negative 100)   to +100 inclusive Display the array and its length (use the len function) Display the average of all the integers in the array Display the number of even integers (how many) Display the number of odd integers (how many) Display the number of integers > 0   (how many) Display the number of integers < 0   (how many) Display the...

  • Create a class with an array of type integer of size 15. Fill the array with...

    Create a class with an array of type integer of size 15. Fill the array with random integers of size 1 to 1000. Sort the array. Print out the contents of the array. Thank you in advance

  • Programming 5_1: Create a Java class named <YourName>5_1 In this class create a main method...

    Programming 5_1: Create a Java class named <YourName>5_1 In this class create a main method, but for now leave it empty. Then write a Java method getAverage which takes an array of integers as it’s argument. The method calculate the average of all the elements in the array, and returns that average. The method should work for an array of integers of any length greater than or equal to one. The method signature is shown below: public static double getAverage(...

  • In Java Create an array of Student objects. Display the students by age in UNSORTED order....

    In Java Create an array of Student objects. Display the students by age in UNSORTED order. Apply the Quick sort and Display the students by age in SORTED order. public class TestQuickStudent { public static void main (String [ ] args ) { /* ***Create your array of Student objects with AT LEAST 5 names */ System.out.println ( " ____________________________");    /* ***LOOP through your array and print out each UNSORTED check by student age */ System.out.println ( " ____________________________");...

  • JAVA I. Using the Event Class created previously, create an array of objects;        II. Demonstrate...

    JAVA I. Using the Event Class created previously, create an array of objects;        II. Demonstrate passing array reference to a method;        III. Demonstrate creating array of objects that prints out only x 0.0 for all objects. PROJECT 5C - ARRAYS Create a new file called " EventArray5C". There are some "challenging" directions in this project. . 1.Prepare a document box (tell me that task(s) the application is to accomplish, how it will accomplish the tasks, the author of...

  • Write a c++ program that does the following Create an integer array of size 30. Assign...

    Write a c++ program that does the following Create an integer array of size 30. Assign -1 to each location in the array indicating that the array is empty. Populate half of the array with random integer values between 100 and 500 inclusive. Use the following formula in order to hash and store each number in its proper position/location. Generated Number Table Size: Should a collision occurs, use linear probing to find next available position location. Use the following probing...

  • We want to create and then initialize an array named A to contain the integers: 4,...

    We want to create and then initialize an array named A to contain the integers: 4, 5, 6, 7. There are multiple ways this can be done. From the list below, select all of the correct ways to create and initialize A. int size = 4; int [] A = new int [size]; A[0] = 4; A[1] = 5; A[2] = 6; A[3] = 7; int [] A = new int [4];       A[0] = 4;       A[1] = 5;...

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