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
How do you implement instruction level parallelism
netineya [11]

Answer:

To obtain substantial performance enhancements, we must exploit ILP across multiple basic blocks.

Explanation:

8 0
3 years ago
2min speech on can teachers be replace by technology​
elena-s [515]

Answer:

The boom of online courses, where anyone can learn from the comfort of one’s own home or office at their own chosen time is the main cause. When online courses made their foray a decade ago, the same question of technology replacing teachers in schools emerged as a major argument. However, if we ask you today whether calculators can replace mathematics teachers at school, what would you say? Sounds weird, right! Do you think calculators which are also a kind of a technological advancement only, are capable enough of themselves, so as to replace the teachers? The answer is obvious. It’s an obvious No!

6 0
2 years ago
3.18: Pizza Pi Joe’s Pizza Palace needs a program to calculate the number of slices a pizza of any size can be divided into. The
alina1380 [7]

Answer:

#program in python.

#variables

slice_area=14.125

pi=3.14159

#read diameter

d=int(input("Enter diameter of pizza:"))

#area of pizza

area=pi*(d/2)*(d/2)

#number of slice

no_slice=int(area/slice_area)

#print slice

print("total silce are:",no_slice)

Explanation:

Declare and initialize a variable "slice_area" with 14.125 which is the area of a pizza slice.Initialize a variable "pi" with 3.14159.Then read the diameter of pizza.Find the area of pizza as "area=pi *d/2*d/2".Divide the total area with area of pizza slice.This will be the number of slice.

Output:

Enter diameter of pizza:20                                                                                                

total silce are: 22

6 0
3 years ago
What was most monumental decision in making a trip to Oregon?
White raven [17]

Answer:

A. The amount of food to take on the journey

Explanation:

Hope you get it right!!

3 0
2 years ago
Read 2 more answers
One critique of determining the effectiveness of the psychodynamic perspective is that its theories are too vague to test. t/f
Feliz [49]
TRUE

Psychodynamic theories are usually too vague to allow a clear scientific test. Modest support for central psychodynamic hypotheses has been provided by Empirical studies. Critics have in the past disputed very many aspects of psychoanalysis including whether it is indeed a science or not. However much this is so, psychoanalysis is a great idea in personality that should never be overlooked.






3 0
3 years ago
Read 2 more answers
Other questions:
  • Troubleshooting comes before diagnosing. Answer: false
    7·1 answer
  • How do I make my own extension for chrome?
    7·1 answer
  • Suppose you are on a desert island and possess exactly 20 coconuts your neighbor Friday is a fisherman and he is willing to trad
    14·1 answer
  • What is your favourite video game??​
    5·2 answers
  • Cryptcat is a Linux distribution that includes hundreds of security and hacking tools, including Nessus and Metasploit. It can p
    11·1 answer
  • Which of the following is true of the poka-yoke approach used for mistake-proofing processes?
    9·2 answers
  • Son opciones de configuración espacio multimedia llamado blog
    9·1 answer
  • In troubleshooting a boot problem, what is the advantage of restoring all BIOS settings to their default values?
    6·1 answer
  • What is malware? a type of virus that spreads through a network connection a type of virus that targets programs and files any p
    8·1 answer
  • If, after fetching a value from memory, we discover that the system has returned only half of the bits that we expected; it is l
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!