Question

In: Computer Science

1. I need a java program that prints the following rows of arrays, like shown [3,5,6...

1. I need a java program that prints the following rows of arrays, like shown

[3,5,6

7, 61, 71,

9, 99, 999,

4, 1, 0]

2. I also need a program that prints the sum of all the arrays

3. and a third program that only prints the elements from row one.

Thanks!

Solutions

Expert Solution


public class Main
{
   public static void main(String[] args) {
int sum;
   int arr[][]={ {3,5,6},{7,61,71},{9,99,999},{4,1,0}};//declare arr of size 4 rows 3 columns
// to print array contents row wise
   for(int i=0;i<4;i++)
   {
   for(int j=0;j<3;j++)
   System.out.print(arr[i][j]+" ");
  
   System.out.print("\n");
   }
   //to print sum row wise
   for(int i=0;i<4;i++)
   {
   sum=0;
   for(int j=0;j<3;j++)
       sum=sum+arr[i][j];
      
       System.out.println("Sum of row "+(i+1) +" is :"+sum);
   }
   //print elements of row 1
   System.out.println("\nThe elements of Row1 are :");
   for(int i=0, j=0;j<3;j++)
   System.out.print(arr[i][j]+" ");
   }//end main()
}//end class


Related Solutions

Java - Text File to Arrays and output ------------------------------------------------------------------------------ I need to have a java program...
Java - Text File to Arrays and output ------------------------------------------------------------------------------ I need to have a java program read an "input.txt" file (like below) and store the information in an respective arrays. This input.txt file will look like below and will be stored in the same directory as the java file. The top line of the text represents the number of people in the group for example. the lines below it each represent the respective persons preferences in regards to the other...
Read a text file into arrays and output - Java Program ------------------------------------------------------------------------------ I need to have...
Read a text file into arrays and output - Java Program ------------------------------------------------------------------------------ I need to have a java program read an "input.txt" file (like below) and store the information in an respective arrays. This input.txt file will look like below and will be stored in the same directory as the java file. The top line of the text represents the number of people in the group for example. the lines below it each represent the respective persons preferences in regards...
Java program problem 1 Come up with an idea for parallel arrays Create the arrays to...
Java program problem 1 Come up with an idea for parallel arrays Create the arrays to hold 5 items in each In the main(), load the arrays with data Then output the entire contents of the arrays Create a method called find1() and pass the 2 arrays to that method. problem 2 In the find1() method, ask the user to enter a value to search for Write logic to search the first array and then output the related data from...
Write the following program in Java. Ask the user to enter the number of rows and...
Write the following program in Java. Ask the user to enter the number of rows and columns for a 2-D array. Create the array and fill it with random integers using (int)(Math.random() * 20) (or whatever number you choose). Then, provide the user with several menu choices. 1. See the entire array. 2. See a specific row. 3. See a specific column. 4. See a specific value. 5. Calculate the average of each row. 6. Calculate the total of each...
Write a Java program to print the pattern of asterisks shown below. For i=1 * For...
Write a Java program to print the pattern of asterisks shown below. For i=1 * For i=2 * * * For i=3 * ** * * * For i=n * * * * * * … … … * * * * * * ……… n
I only need to update this JAVA program to be able to : 1 ) Exit...
I only need to update this JAVA program to be able to : 1 ) Exit cleanly after creating the chart 2 ) change the pie chart to a perfect circle rather than an oval 3 ) provide a separate class driver import java.awt.Color; import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.Rectangle; import java.util.Scanner; import javax.swing.JComponent; import javax.swing.JFrame; // class to store the value and color mapping of the // pie segment(slices) class Segment { double value; Color color; // constructor public...
Write a c program that reads a .img file by rows and columns and prints out...
Write a c program that reads a .img file by rows and columns and prints out the arrays. The .img file contains h(the height) and w(the width) of the text size. An example .img file would be: 2 4 DFJSK HJ5JF HFDY5
JAVA I need to write a code that calculates mean and standard deviation using arrays and...
JAVA I need to write a code that calculates mean and standard deviation using arrays and OOP. This is what I have so far. I'm close but my deviation calculator method is throwing errors. Thanks so much :) import java.util.Scanner; import java.util.Arrays; public class STDMeanArray { private double[] tenUserNums = new double[10];//Initialize an array with ten index' private double mean; private double deviation; Scanner input = new Scanner(System.in);//create new scanner object /*//constructor public STDMeanArray(double tenUserNum [], double mean, double deviation){...
java program Create a program that creates and prints a random phone number using the following...
java program Create a program that creates and prints a random phone number using the following format: XXX-XXX-XXXX. Make sure your output include the dashes.  Do not let the first three digits contain an 8 or 9 (HINT: do not be more restrictive than that) and make sure that the second set of three digits is not greater than 773. Helpful Hint:   Think though the easiest way to construct the phone number. Each digit does do not have to be determined...
*Java program* Use while loop 1.) Write a program that reads an integer, and then prints...
*Java program* Use while loop 1.) Write a program that reads an integer, and then prints the sum of the even and odd integers. 2.) Write program to calculate the sum of the following series where in is input by user. (1/1 + 1/2 + 1/3 +..... 1/n)
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT