Question

in java / You will: // 1- create a square 2 dimensional array of random size...

in java

/ You will:

// 1- create a square 2 dimensional array of random size (less than 11)

// 2- fill the array with random integers from 1 to the size limit

// 3- print the array

// 4- prompt to see if the user wants to do another

//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

// 1- The square can use the same random value for x and y. Don't allow 0 size arrays.

// 2- Maybe a nested set of for loops? to go from row(0) col(0) to row(x)col(x)

// So that the values in the array aren't huge keep them limited to a range set by the number of values in a row (size){ A 6x6 square will contain integers smaller than 7, a 3x3 square will have integers smaller than 4}

// 3- Print it in the square format (On screen it will look like a rectangle but as long as the number of rows and columns are the same we will consider it a square.

// 4- If you used a Do loop to start the square the While condition could be held to check a sentinel the user enters as “yes”.

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

//Program

========================================================

import java.util.Scanner;
class Array2d{

    static int[][] createArray(int x,int y){
        int arr[][]=new int[x][y];
        for(int i=0;i<x;i++){
            for (int k=0;k<y;k++){
                arr[i][k]= (int) Math.round(Math.random()*(x-1))+1;
            }
        }
        return arr;
    }

    static void display(int[][] arr,int x,int y){
        for(int i=0;i<x;i++){
            for (int k=0;k<y;k++){
                System.out.print(arr[i][k]+" ");
            }
            System.out.println();
        }
    }


    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String choice="";
        do{
            int x = (int) Math.round(Math.random()*9)+1;
            int y = (int) Math.round(Math.random()*9)+1;
            System.out.println(x+" "+y);
            int arr[][]= createArray(x, y);
            display(arr, x, y);
            System.out.print("Wants to do another(yes/no) : ");
            choice = sc.nextLine();
        }while(choice.compareTo("yes")==0);
    }
}

====================================================

//output

======================================================

please appreciate my effort to solve your problem by hit like button

and comment below in case having any doubt

Add a comment
Know the answer?
Add Answer to:
in java / You will: // 1- create a square 2 dimensional array of random size...
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
  • Assignment Input from the user 9, 64-bit, floating-point values as a 3x3, row-major, multi-dimensional array. This...

    Assignment Input from the user 9, 64-bit, floating-point values as a 3x3, row-major, multi-dimensional array. This will be the 3x3 matrix. Then, input 3, 64-bit, floating-point values. This will be a single-dimensional array and is the vector. Your program will simply ask the user to enter matrix values. Remember, there are 9 of these, but they need to be stored into a 3x3 multi-dimensional array (row-major). Then, your program will ask for the vector values, which will be stored into...

  • I should use the array and loop to create a java program according to the instruction,...

    I should use the array and loop to create a java program according to the instruction, but I have no idea how to do it. Introduction This lab assignment continues to give you practice using loops, particularly loops with variable termination conditions, and it also provides you an opportunity to use one-dimensional arrays. Recall that an array is used to store a collection of data. The data can be values of Java primitive data types or else objects (for instance,...

  • create a new Java application called "Scorer" (without the quotation marks) that declares a two-dimensional array...

    create a new Java application called "Scorer" (without the quotation marks) that declares a two-dimensional array of doubles (call it scores) with three rows and three columns and that uses methods and loops as follows. Use a method containing a nested while loop to get the nine (3 x 3) doubles from the user at the command line. Use a method containing a nested for loop to compute the average of the doubles in each row. Use a method to...

  • Create a square array and fill out as shown below. Use nested loop for this step....

    Create a square array and fill out as shown below. Use nested loop for this step. 1 3 5 7 9 2 4 6 8 10 3 5 7 9 11 4 6 8 10 12 5 7 9 11 13 Then create two 1D arrays to with row and column sum of the items. You have then 15 25 35 45 55 for the column sum, and 25 30 35 40 45 for the row sum. Print row and...

  • Create a square array and fill out as shown below. Use a nested loop for this...

    Create a square array and fill out as shown below. Use a nested loop for this step. 1 3 5 7 9 2 4 6 8 10 3 5 7 9 11 4 6 8 10 12 5 7 9 11 13 Then create two 1D arrays to with row and column sum of the items. You have then 15 25 35 45 55 for the column sum, and 25 30 35 40 45 for the row sum. Print row...

  • Make a program using Java that asks the user to input an integer "size". That integer...

    Make a program using Java that asks the user to input an integer "size". That integer makes and prints out an evenly spaced, size by size 2D array (ex: 7 should make an index of 0-6 for col and rows). The array must be filled with random positive integers less than 100. Then, using recursion, find a "peak" and print out its number and location. (A peak is basically a number that is bigger than all of its "neighbors" (above,...

  • Which of the following is False about arrays in Java? A data structure for storing a...

    Which of the following is False about arrays in Java? A data structure for storing a collection of data of the same type. Length of array can be changed after creation of array. A Java array is an object. Array's index cannot be negative or bigger than array's length. Which of the following can print out all elements in array? int[] [] items - { {0, 1, 3, 4), {4, 3, 99, 0, 7), {3, 2} } ; for (int...

  • 1.The code box below includes a live 2 dimensional array variable called gridNums. This array holds...

    1.The code box below includes a live 2 dimensional array variable called gridNums. This array holds integers. You cannot see its declaration or initialization. What value is in the zeroth (initial) position of the second row? Print this array entry to the console. (Note: remember that the second row is actually row 1). Enter your code in the box below. 2.The code box below includes a live 3x3 2-dimensional array variable called fredsNums. This array holds integers. You cannot see...

  • c++ help please! Create a 2D character array in your main function and use nested for...

    c++ help please! Create a 2D character array in your main function and use nested for loops to fill the array with the letter ‘e’ to represent empty spaces. Create a function to print the board on the screen using a nested for loop. The function header is: void printBoard (char board [][3]) Create a function that checks whether a particular space has already been filled. If the space is filled it returns a boolean value of true, otherwise false....

  • Write a java program that create a 2 dimensional array of type double of size 10...

    Write a java program that create a 2 dimensional array of type double of size 10 by 10. Fill the array with random numbers using a random number generator. Print the array contents. Write a java program that creates a file called data.txt that uses the PrintWriter class. Write the numbers 1 to 42 into the file. Close the file. Attach both files. Thank you in advance

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