Write some instructions to do the following. Ask the user for the row number and
ID: 3687151 • Letter: W
Question
Write some instructions to do the following. Ask the user for the row number and read it. Ask the user for the column number and read it. Ask the user for the sale amount and read it. Add the sale amount to the value in sales from problem 1 using the row and column given. 3. Write instructions that will find the total for each row, the total for each column, and the grand total for the array sales from problem 1. Use the following to hold the totals. 4. Write a method that will accept a 2-dimensional array of doubles and return the total of the numbers in the array. 5. What is a ragged array? 6. Write an instruction to create a ragged array named "distances" with the following values:Explanation / Answer
2 Ans) Answer for the second is:
import java.util.Scanner;
public class MultiArrayEx{
public static void main(String[] args)
{
int iarr[][] = new int[2][2];
Scanner sc=new Scanner(System.in);
int x,y;
for (int i = 0; i < iarr.length; i = i + 1)
{
for(int j=0; j < iarr[i].length; j = j + 1)
{
System.out.println("enter row number: ");
x=sc.nextInt();
System.out.println("enter column number: ");
y=sc.nextInt();
System.out.println("Enter your sale amount: ");
float sale=sc.nextInt();
System.out.print("value for "+x+" row and "+y+" column is "+sale);
System.out.print(" ");
}
System.out.println(" ");
}
}
}
4 Ans) 4th question answer is:
int[] sumEqualLengthArrays(int[] a, int[] b) {
int[] result = new int[a.length];
for (int i = 0; i < a.length; i++)
result[i] = a[i]+b[i];
return result;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.