Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int[][] array = new int[2][3];
- array[0][0] = 1;
- array[0][1] = 2;
- array[1][0] = 3;
- array[1][1] = 4;
- array[0][2] = 5;
- array[1][2] = 6;
- public class Application {
- public static void main(String[] args) {
- int[][] array = new int[2][3];
- array[0][0] = 1;
- array[0][1] = 2;
- array[1][0] = 3;
- array[1][1] = 4;
- array[0][2] = 5;
- array[1][2] = 6;
- int[] newArray = new int[array.length];
- for (int i = 0; i < array.length; i++) {
- for (int j = 0; j < array[i].length; j++) {
- newArray[i] += array[i][j];
- }
- }
- Arrays.stream(newArray).forEach(System.out::println);
- }
- }
- package array;
- /**
- *
- * @author vvm
- */
- public class ArrayCount {
- public static void main(String[] args) {
- int[][] array = new int[2][3];
- for (int i = 0; i < 2; i++) {
- for (int j = 0; j < 3; j++) {
- array[i][j] = i+1;
- }
- }
- for (int i = 0; i < 2; i++) {
- System.out.println("");
- for (int j = 0; j < 3; j++) {
- System.out.print(" array[" + i + "]" + "[" + j + "]" + " = " + array[i][j]);
- }
- }
- }
- }
- int rowsCount = array[0].length;
- for(int row = 0; row < rowsCount; row++)
- {
- int sum = 0;
- for(int i = 0; i < array.length; i++)
- {
- int cell = array[i][row];
- sum += cell;
- // debug (remove next line if not needed!)
- System.out.print(cell + (i < array.length - 1 ? " + " : " = "));
- }
- System.out.println(sum);
- }
Add Comment
Please, Sign In to add comment