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
katrin2010 [14]
2 years ago
7

Write a Java program that creates a two-dimensional array of type integer of size x by y (x and y must be entered by the user).

The program must fill the array with random numbers from 1 to 9. Then, the program must print the original array and the elements that are in even columns of the array.
Computers and Technology
1 answer:
Law Incorporation [45]2 years ago
3 0

Answer:

The java program is as follows:

import java.util.*;

public class Main{

public static void main(String[] args) {

 Scanner input = new Scanner(System.in);

 Random r = new Random();

 int x, y;

 x = input.nextInt();  

 y = input.nextInt();

 int[][] Array2D = new int[x][y];

 for(int i = 0; i < x ; i++){

     for(int j = 0; j < y; j++){          Array2D[i][j] = r.nextInt(9) + 1;      }

 }

 for(int i = 0; i < x ; i++){

     for(int j = 0; j < y; j++){          System.out.print(Array2D[i][j]+" ");      }

     System.out.println();

 }

 

 for(int i = 0; i < x ; i++){

     for(int j = 1; j < y; j+=2){          System.out.print(Array2D[i][j]+" ");      }

     System.out.println();

 }

}

}

Explanation:

This creates a random object

 Random r = new Random();

This declares x and y as integers

 int x, y;

This gets input for x

 x = input.nextInt();  

This gets input for y

 y = input.nextInt();

This declares the 2D array

 int[][] Array2D = new int[x][y];

The following iteration populates the array with integers 1 to 9

<em>  for(int i = 0; i < x ; i++){</em>

<em>      for(int j = 0; j < y; j++){          Array2D[i][j] = r.nextInt(9) + 1;      }</em>

<em>  }</em>

The following iteration prints all elements of the array

<em>  for(int i = 0; i < x ; i++){</em>

<em>      for(int j = 0; j < y; j++){          System.out.print(Array2D[i][j]+" ");      }</em>

<em>      System.out.println();</em>

<em>  }</em>

The following iteration prints all elements on the even column

<em>  for(int i = 0; i < x ; i++){</em>

<em>      for(int j = 1; j < y; j+=2){          System.out.print(Array2D[i][j]+" ");      }</em>

<em>      System.out.println();</em>

<em>  }</em>

<em />

You might be interested in
The function below takes a single string parameter: sentence. Complete the function to return everything but the middle 10 chara
dolphi86 [110]

Answer:

def get_middle_ten(sentence):

   ind = (len(sentence) - 12) // 2

   return sentence[ind:ind + 12]

# Testing the function here. ignore/remove the code below if not required

print(get_middle_twelve("abcdefghijkl"))

print(get_middle_twelve("abcdefghijklmnopqr"))

print(get_middle_twelve("abcdefghijklmnopqrst"))

7 0
3 years ago
Which is the correct process for opening a blank spreadsheet?
Step2247 [10]
The best way of doing this would be when you are opening a document application, the first thing that you would do in this case in to click "new". And by clicking new, you would have a fresh new spread sheet.
5 0
2 years ago
ANSWER QUICKLY!
patriot [66]

Answer:

It is bit { measurement used to quantify computer data. }

7 0
3 years ago
Why does my Chromebook keep on turning my new tabs into clever tabs?
Alina [70]

Answer:

Ok, so it's not letting me submit a text response, so I'll attach an image of my answer.

Explanation:

6 0
2 years ago
Read 2 more answers
What are ways to access Tasks view in Outlook? Check all that apply. Select To-Do List or Task Folder. View daily task lists in
SVETLANKA909090 [29]

Answer:

A. B. D. E.

Explanation:

edg 2021

8 0
3 years ago
Read 2 more answers
Other questions:
  • . the web is based on the ________ protocol
    6·1 answer
  • Why would a designer choose to use an isometric sketch rather than a perspective sketch to share their idea with a design team m
    14·1 answer
  • Colin Mackay Inc., a software company with its head office in Amsterdam, has employees across three continents. The company's pr
    10·1 answer
  • You are the IT administrator for a small corporate network. You have installed the Windows Server 2016 operating system on a ser
    12·1 answer
  • (You don’t have to answer it’s just for you for points. Here is you’re riddle)
    9·2 answers
  • Which advertising medium has the widest reach on a global front?
    12·1 answer
  • What are some other features of sending attachments in Outlook 2016? Check all that apply.
    9·2 answers
  • Brian gathers data from his classmates about the computers they own such as the type of operating system, the amount of memory,
    11·1 answer
  • How would you open the web browser in Linux and still have access to the Linux terminal?
    14·1 answer
  • The range of an area where users can access the Internet via high-frequency radio signals transmitting an Internet signal from a
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!