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
What are two reasons a network administrator would use cdp.
Ulleksa [173]

Answer:

To obtain VLAN information from directly connected switches. To determine the status of network services on a remote device. To determine the status of the routing protocols between directly connected routers .

Explanation:

6 0
2 years ago
Back in the mid-1800s, who was one of the first artists to retouch negatives to reduce or eliminate any imperfections in the sho
tia_tia [17]

Answer:

Calvert Richard Jones

Explanation:

Just five years later, in 1846, the first known act of photographic retouching was performed by a Welsh colleague of Talbot's named Calvert Richard Jones, or perhaps by one of Jones's associates

6 0
2 years ago
Read 2 more answers
Shelly and Donna are discussing System Restore. Shelly says when the System Restore program creates and saves a copy of your com
pav-90 [236]
The answer is D, because it's called a back-up.
4 0
3 years ago
How many different bit strings are there of length 8 that contain the string 0000?
Nataly_w [17]

Answer:

answer is 8! / (4! * 4!). Which gives a value of 70.

Explanation:

we have 8 places, we’re going to pick 4 places to put the zeros, it is 8! / (4! x 4!)

3 0
2 years ago
The scheme where you can find the greatest common divisor of two integers by repetitive application of the division algorithm is
gavmur [86]

Answer:

False

Explanation:

The scheme where you can find the greatest common divisor (GCD) of two integers by repetitive application of the division algorithm is known as Euclidean Algorithm.

The Euclidean Algorithm for calculating GCD of two numbers X and Y can be given as follows:

  • If X=0 then GCD(X, Y)=Y since the Greatest Common Divisor of 0 and Y is Y.
  • If Y=0 then GCD(X, Y)=X since the Greates Common Divisor of 0 and X is X.
  • Let R be the remainder of dividing X by Y assuming X > Y. (R = X % Y)
  • Find GCD( Y, R ) because GCD( X, Y ) = GCD(Y, R ).
  • Repeat the above steps again till R = 0.

4 0
3 years ago
Other questions:
  • Which wireless technology has a typical transfer rate of 1 Mbps to 3 Mbps at distances up to about 10 meters?
    7·1 answer
  • Amazon Web Services (AWS): Group of answer choices a) forms a majority percentage of Amazon's overall revenue. b) was introduced
    15·1 answer
  • TLO 06 Active Directory Domain and Trusts tool is used to move servers between site in an AD Infrastructure.a. Trueb. False
    14·1 answer
  • Markup is best defined as
    11·1 answer
  • Conduct online research to determine specific conflict-resolution and management techniques and skills that would be beneficial
    5·1 answer
  • Which best describes a difference between transcription and DNA replication
    8·2 answers
  • Cuántos tipos de grua existen en el mundo​
    7·1 answer
  • Iciples UI
    12·1 answer
  • What is an occupation?​
    6·1 answer
  • Ideally, Internet of Things (IoT) devices have the ability to:
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!