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
What is a Database, Flat file and Relational Database?
Marta_Voda [28]

Answer:

A flat file database stores data in a single table structure. A relational database uses multiple table structures, cross-referencing records between tables. Tables in both organize records in rows, with each column containing a single piece of data in the record.

8 0
2 years ago
Write a C++ program that computes student grades for an assignment as a percentage given each student's score and the total poin
aivan3 [116]

Answer:

See Explaination

Explanation:

/ Header files section

#include <iostream>

#include <fstream>

#include <iomanip>

#include <string>

#include <cmath>

using namespace std;

// start main function

int main()

{

// variables declaration

string fileName;

string lastName;

double score;

double total;

double grade;

string description;

// prompt the user to enter the input file name

cout << "Enter the input file name: ";

cin >> fileName;

// open the input file

ifstream infile;

infile.open(fileName);

// exit from the program if the input file does not open

if (!infile)

{

cout << fileName << " file cannot be opened!" << endl;

exit(1);

}

// repeat the loop for all students in the file

infile >> lastName;

while (infile)

{

infile >> score;

infile >> total;

// compute the grade

grade = score / total * 100;

// find the grade's description

if (grade > 90)

description = "Excellent";

else if (grade > 80)

description = "Well Done";

else if (grade > 70)

description = "Good";

else if (grade >= 60)

description = "Need Improvement";

else

description = "Fail";

// display the result of each student

cout << lastName << " " << setprecision(0) << fixed << round(grade) << "% " << setprecision(5) << fixed << (grade * 0.01) << " " << description << endl;;

infile >> lastName;

}

// close the input file

infile.close();

system("pause");

return 0;

} // end of main function

8 0
3 years ago
Mia’s bank statement shows a closing balance of $75.65. There are no outstanding check or deposit. Her checkbook show a balance
ankoles [38]
The difference ($2.30) could be due to a fee for an ATM withdrawal, a math error, writing in the wrong amount
3 0
3 years ago
Every call to a recursive function has its own code and its own set of ____ and local variables
777dan777 [17]

Answer: Parameters

Explanation:

Whenever a call to a recursive function is made, then the function has its own code and its own set of parameters with local variables. These parameters are within the scope of the recursive function. For example while finding the factorial of a number we are given the function with parameter such as int recursive(int n) where int n is a parameter passed into the function.

8 0
3 years ago
How are computers used in medical sector? Any 3 meaningful points.
Vladimir79 [104]

Answer:

Computers such as the Cathode Ray Oscilloscopes are used to measure the blood pressure en heart beats in BPM.

Computers such small locomotive surgical cameras which provide surgeon's sight in the inner body of the victim during surgery.

4 0
3 years ago
Read 2 more answers
Other questions:
  • What is the difference in adware and spyware
    11·2 answers
  • With the help of what memory a computer can read as well as write or modify data
    14·2 answers
  • At one college, the tuition for a full-time student is $6,000 per semester. It has been announced that the tuition will increase
    12·1 answer
  • Scientists measure an object’s mass in kilograms and its weight in newtons. If you knowthe amount of mass of an object in kilogr
    5·1 answer
  • What feature is not included in most DTP programs?
    9·1 answer
  • Consider the method below, which prints the digits of an arbitrary positive integer in reverse order, one digit per line. The me
    7·1 answer
  • You want to substitute one word with another throughout your document. What tool(s) should you use?
    9·1 answer
  • True or false A job analysis weight the positives and negative of a given career
    13·1 answer
  • Tests that replace_punctuation() replaces 1 exclamation point and 2 semicolons in "we'll continue our quest in space. there will
    14·1 answer
  • :) :) :):):):)):):):)):)/):))::)):):):):):)):):)):):))/):):))
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!