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.

Answers

Answer 1

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

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

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

 }

The following iteration prints all elements of the array

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

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

     System.out.println();

 }

The following iteration prints all elements on the even column

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

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

     System.out.println();

 }


Related Questions

After performing addition operation such as AX=18, BX=19 which Flags will be
affected

Answers

Answer:

Carry Flag (CF) - this flag is set to 1 when there is an unsigned overflow. ...

Zero Flag (ZF) - set to 1 when result is zero. ...

Sign Flag (SF) - set to 1 when result is negative. ...

Overflow Flag (OF) - set to 1 when there is a signed overflow.

A constructor can be overloaded with more than one function which has the same name but with what two different things

Answers

Answer:

i. Number of parameters

ii. Type of parameters

Explanation:

When there are two or more constructors, definitely with the same name, in a given class, then the constructors are said to be overloaded. An overloaded constructor appears declared many times in a class but each time with different number of parameters and/or type of parameters.

For example, given a class Test, the following combination of constructors can exist;

i. public Test(int x){

   

 }

ii. public Test(String m){

     

  }

iii. public Test(int a, String b){

 

}

The following should be noted;

In the case of combination (i) and (ii), the constructors have the same number of parameters but different type of parameter. In other words, they both have 1 parameter but while the first one has a parameter type of int, the second has a parameter type of String.

In the case of combination (ii) and (iii), the constructors have different number of parameters and of course different type of parameters. In other words, the second constructor has 1 parameter of type String while the third constructor has 2 parameters of types int and String.

What is the Best IPTV service provider in the USA?

Answers

Answer:

Comstar.tv.

Explanation:

Comstar.tv. Comstar.tv is the best IPTV provider offering HD 7300+ channels, 9600+ Movies and 24/7 on demand TV shows on your TV, Phone, Laptop or tablet.

Reverse Word Order: Write a program that reverses the order of the words in a given sentence. This program requires reversing the order of the words wherein the first and last words are swapped, followed by swapping the second word with the second to last word, followed by swapping the third word and the third to last words, and so on.

Answers

Answer:

function reverseArray(arr) {

   if (arr.length > 1) {

      arr = [arr[arr.length-1], ...reverseArray(arr.slice(1, -1)), arr[0]]

   }

   return arr;

}

function reverseSentence(sentence) {

   let words = reverseArray( sentence.split(" ") );

   return words.join(" ");

}

console.log( reverseSentence("The quick brown fox jumps over the lazy dog's back") );

console.log( reverseSentence("one two three") );

console.log( reverseSentence("one two") );

console.log( reverseSentence("Single") );

Explanation:

This is a solution in javascript leveraging several powerful constructs in that language, such as the spread operator.

Mencione como la electricidad evoluciono la vida el ser humano.
AYUDA

Answers

Answer:

La electricidad es el conjunto de fenómenos físicos relacionados con la carga eléctrica y los campos eléctricos y también con el electromagnetismo. Dado que la energía eléctrica es una fuente importante de energía en la vida cotidiana, las palabras "electricidad" y "corriente" a menudo se usan indistintamente en el habla cotidiana. Sin embargo, la electricidad también incluye otros fenómenos fácilmente reconocibles como los rayos y la electricidad estática.

La electricidad tiene muchas aplicaciones técnicas. Por lo tanto, la ingeniería eléctrica se explora y se desarrolla más en la ingeniería eléctrica. A diferencia de muchos otros fenómenos físicos, muchos de los fenómenos asociados con la electricidad pueden medirse y calcularse previamente con gran precisión.

La electricidad es un fenómeno natural. La más conocida es la ocurrencia de rayos, que es causada por una diferencia de potencial en la atmósfera. Algunos peces, como la anguila eléctrica, también son capaces de generar electricidad. Además, los sistemas nerviosos animal y humano funcionan con señales eléctricas.

With what software tool can you see the applications that are currently runni
your computer?
Application Manager
Task Scheduler
Task Manager
Device Manager
None of the above

Answers

Answer:

Task Manager

Explanation:

On windows, you can press Ctrl + Esc and it will open Task Manager.

You will see all the currently running programs and the amount of resources they are currently using.

What mistake might you make related to changing the data in a cell that's used in a formula?

Answers

Answer:

ojalat sirve

Explanation:

Cuando en una fórmula, en vez de indicar una celda, fila o columna estamos enlazando una hoja de cálculo o libro, debemos hacerlo con comilla simple. Si empleamos otro signo o símbolo separador, la fórmula no entenderá correctamente lo que le estamos indicando.

Why might you use a navigation form instead of tab pages? The navigation form allows for several levels and sublevels to be collected. The navigation form allows for duplicate records of information to be collected. The navigation form requires all entries to be complete before adding to a database. The navigation form requires report headers and footers to make publication neater.

Answers

Answer:

Access includes a Navigation Control that makes it easy to switch between various forms and reports in your database. A navigation form is simply a form that contains a Navigation Control. Navigation forms are a great addition to any desktop database.

Explanation:

yes

Answer:

answer c

Explanation:

correct answer on edge

Write a program that lets the user enter the total rainfall for each of 12 months into an array of doubles. The program should calculate and display the total rainfall for the year and the average monthly rainfall. Use bubble sort and sort the months with the lowest to highest rain amounts. Use the binary search and search for a specific rain amount. If the rain amount is found, display a message showing which month had that rain amount. Input Validation: Do not accept negative numbers for monthly rainfall figures.

Answers

Answer:

Program approach:-

Using the header file.Using the standard namespace I/O.Define the main function.Check whether entered the value is negative.Find the middle position of the array.Display message if value not found.Returning the value.

Explanation:

Program:-

//required headers

#include <stdio.h>

#include<iostream>

using namespace std;

//main function

int main()

{   double rain[12], temp_rain[12], sum=0, avg=0, temp;

   int month=0, i, j, n=12, low=0, mid=0, high=12, x, found=0;

   char month_name[][12]={"January", "February", "March", "April", "May", "June",

   "July", "August", "September", "October", "November", "December"};

 

   //store input values to arrays rain and temp_rain

   while(month<n)

   {   cout<<"Enter the total rainfall for month "<<month+1<<" :";

       cin>>temp;

     

       //check whether the entered value is negative

       if(temp<0)

       {   cout<<"Enter a non negative value"<<endl;

       }

     

       else

       {   rain[month]=temp;

           temp_rain[month]=temp;

         

           //total sum is found out and stored to sum

           sum+=temp;

           month++;

       }

   }

 

   //find average rainfall

   avg=sum/n;

 

   //display total and average rainfall for the year

   cout<<"Total rainfall for the year: "<<sum<<endl;

   cout<<"Average rainfall for the year: "<<avg<<endl;

 

   //perform bubble sort on temp_rain array

   for(i=0; i<n-1; i++)    

   {   for (j=0; j<n-i-1; j++)

       {   if (temp_rain[j]>temp_rain[j+1])

           {

               temp=rain[j];

               temp_rain[j]=temp_rain[j+1];

               temp_rain[j+1]=temp;

           }

       }

   }

   //get search value and store it to x

   cout<<"Enter the value to search for a specific rain amount: ";

   cin>>x;

   //perform binary search on temp_rain array

   while (low<=high)

  {

      //find the middle position of the array

      int mid=(low+high)/2;

      //if a match is found, set found=1

      if(x==temp_rain[mid])

      {   found=1;

          break;

      }

       //ignore right half if search item is less than the middle value of the array

      else if(x<temp_rain[mid])

          high=mid-1;

       //ignore left half if search item is higher than the middle value of the array

      else

          low=mid+1;

  }

 

   //if a match is found, then display the month for the found value

   if(found==1)

   {

       for(i=0; i<n; i++)

       {   if(x==rain[i])

               cout<<"Found matching rainfall for this month: "<<month_name[i];

         

       }

     

   }

 

   //display message if value not found

   else

       cout<<"Value not found.";

 

   return 0;

}

Which of the following statements is NOT true regarding the Security Configuration and Analysis (SCA) tool?

a. It evaluates the current security state of computers in accordance with Microsoft security recommendations.
b. It allows an administrator to analyze a computer and compare its configuration settings with a baseline.
c. It can apply a baseline to force current computer settings to match the settings defined in the baseline.
d. It uses security templates to store the settings that make up baselines.

Answers

Answer: a. It evaluates the current security state of computers in accordance with Microsoft security recommendations

Explanation:

The Security Configuration and Analysis tool allows the configuration of local computers through the application of the settings in a security template to the local policy.

This allows an administrator to analyze a computer and compare its configuration settings with a baseline. The Security Configuration and Analysis (SCA) tool also uses security templates to store the settings that make up baselines.

Therefore, based on the options given, the correct option is A as the SCA tool doesn't evaluate the current security state of computers in accordance with Microsoft security recommendations.

Other Questions
What is the value of x in the diagram? Why does Malcolm lie about himself to Macduff? A metal paperweight is in the shape of a cylinder. The paperweight has the height of 1.5 inches and a diameter of 2 inches. How much does the paperweight weigh if 1 cubic inch weighs 1.8 ounces? Round to the nearest tenth! What states can I legally own a pet bat? i need help can someone help mety HELPPPPPPPPPP What is the meaning of the phrase tame the land as it is used in the passage above? O A) It means that the land was unsafe. OB) It means that the land was not settled. oc) It means that the land was not farmed. OD) It means that the land was abandoned. Evaluate the integral. 17/ (x^3 27) dx Mary's bicycle tire has a radius of 40 cm. How far has Mary travelled if her tire has made 50 complete rotations? An employee's total weekly pay is calculated by multiplying the hourly wage and number of regular hours plus any overtime pays which in turn is calculated as total overtime hours multiplied by 1.5 times the hourly wage. Write a program that takes as inputs the hourly wage, total regular hours, and total overtime hours and prints an employee's total weekly pay. How do I do this? Im confused Compare the solubility of silver iodide in each of the following aqueous solutions: a. 0.10 M AgCH3COOb. 0.10 M NaI c. 0.10 M KCH3COO d. 0.10 M NH4NO3 1. More soluble than in pure water. 2. Similar solubility as in pure water. 3. Less soluble than in pure water. Find the edge length = you need to come up with investigation question, to help inform your decision.Think about how land, water, and air absorb and release Thermal energy and then formulate your hypothesis I need some Investigation questions about how land, water, and air absorb and release Thermal energy :,) Subject: science What is the correct written expression for the variable expression: (3 - x)/73 divided by the difference of 7 and xorthe difference of 3 divided by 7 and x Statement of Cash FlowsIndirect MethodThe following balances are available for Chrisman Company:December 31 2017 2016 Cash $9,700 $12,100 Accounts receivable 24,300 18,200 Inventory 19,300 32,200 Prepaid rent 10,900 7,300 Land 90,900 90,900 Plant and equipment 485,000 363,800 Accumulated depreciation (78,800) (36,400) Totals $561,300 $488,100 Accounts payable $14,600 $12,100 Income taxes payable 3,600 6,100 Short-term notes payable 42,400 30,300 Bonds payable 91,000 121,000 Common stock 242,500 181,900 Retained earnings 167,200 136,700 Totals $561,300 $488,100 Bonds were retired during 2017 at face value, plant and equipment were acquired for cash, and common stock was issued for cash. Depreciation expense for the year was $42,400. Net income was reported at $30,500. Required:Prepare a statement of cash flows for 2017 using the indirect method in the Operating Activities section. Use the minus sign to indicate cash payments, cash outflows, or decreases in cash. Which linear inequality is represented by the graph? Im timed hurry plz the yuan dynasty is credited with all of the following except the electrolyte does not need heating to keep it in its molten state; why? What advice would you give someone with the following issues? "A passive smoker will experience the similar effect as an active smoker" Do you agree with the opinion? Justify.