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]
3 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]3 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
To get a sense of your digital footprint, you should: Question 2 options: Google yourself regularly, and monitor what your frien
masha68 [24]
Let us examine the given answers.

a) Google yourself regularly, and monitor what your friends post.
  Verdict: This answer is correct, but it is also necessary to look for yourself on other search engines.

b) Google yourself once a year
  Verdict: Once a year is better than doing nothing, but more than once a year is preferable.

c) Google yourself every five years.
  Verdict: The time interval is too long. Your reputation could easily be damaged, or your identity could be stolen in less than 5 years.

d) Delete all your accounts and start fresh.
   Verdict: This will not solve the problem of having your reputation damaged, or having your identity stolen. Information on the web is preserved ins storage vaults for long periods of time.

Answer: 
Google yourself regularly, and monitor what your friends post. Also, search for your name on other search engines.

3 0
3 years ago
How can I use the word technology in a sentence
romanna [79]


Technology is being changed everyday.

Technology is everywhere.

How is technology helping us?

Everything has technology

Hope it helps :)

Hope the sentences help you 


8 0
3 years ago
Read 2 more answers
Wesellyoubuy, a consumer electronics company, received consumer complaints about its employees not being able to communicate wit
Salsk061 [2.6K]

Answer:

customer satisfaction

Explanation:

The consumer electronics company started a new training program for the consumer service employees as the company found that the consumer service employees were following the same strategy to address all types of consumer issues due to which they were not able to communicate with consumers properly.

This leads to improvement in service ratings and sales.

In this scenario, the consumer service team improved <u>customer satisfaction</u>

5 0
3 years ago
What output will be produced by the following code?
Oduvanchick [21]

Answer:

The condition evaluated to false!

Explanation:

lets attach line numbers to the given code snippet

  1. public class SelectionStatements {
  2.    public static void main(String[] args) {
  3.    int number = 25;
  4.    if(number % 2 == 0)
  5.    System.out.print("The condition evaluated to true!");
  6.    else
  7.    System.out.print("The condition evaluated to false!");
  8.    }
  9. }
  • In Line 3: An integer number is declared and assigned the value 25
  • Line 4 uses the modulo operator (%) to check if the number (25) is evenly divided by 2. This however is not true, so line 5 is not executed
  • The else statement on line 6- 7 gets executed

4 0
3 years ago
Object-oriented programming allows you to derive new classes from existing classes. This is called
Umnica [9.8K]

Answer: Inheritance

Explanation: Inheritance is the feature that is displayed by the class where it happens to acquire the properties of the other classes and exhibit it. the inheriting nature of the class is seen in two different categories -superclass and subclass. It is a concept that is usually followed in the object -oriented programming. The reason for the inheritance is to reuse the element and their properties of other class.

8 0
3 years ago
Other questions:
  • Which expansion slot is used by an NVMe compliant device?
    9·1 answer
  • The amount you pay your insurer for your insurance plan is which of the following?
    14·1 answer
  • You have created shared folders for all your companies departments and assigned the appropriate permissions. everyone can access
    8·1 answer
  • Write a program that reads an integer, and then prints the sum of the even and odd integers.
    8·1 answer
  • Which steps do you follow to create a graph?
    5·2 answers
  • Which key retains its uniqueness even after you remove some of the fields?
    14·1 answer
  • Which of these represents the output of NOT logic? It is the inverse of the input. It is the expression of the input. It is the
    7·2 answers
  • Calculator is an example of
    14·1 answer
  • Under which tab would you look to find the Show in Groups and advanced sort options for messages in Outlook?
    11·2 answers
  • Which of the following industries utilize computer science?
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!