Advertisement
Guest User

Untitled

a guest
Jul 22nd, 2018
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.04 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class SumRow {
  4.  
  5. public static void main(String[] args) {
  6. // TODO Auto-generated method stub
  7. int[][] twoDArray = {{1, 2, 3},
  8. {4, 5, 6},
  9. {7, 8, 9}};
  10. System.out.println("Row 0, 1, or 2?");
  11. sum(twoDArray);
  12. }
  13.  
  14. private static void sum(int[][] twoDArray) {
  15. // TODO Auto-generated method stub
  16. Scanner sc = new Scanner(System.in);
  17. int input = sc.nextInt();
  18. if(input == 0) {
  19. System.out.println(twoDArray[0][0] + " + " + twoDArray[0][1] + " + " + twoDArray[0][2] + " = " + (twoDArray[0][0] + twoDArray[0][1] + twoDArray[0][2]));
  20. }
  21. else if(input == 1) {
  22. System.out.println(twoDArray[1][0] + " + " + twoDArray[1][1] + " + " + twoDArray[1][2] + " = " + (twoDArray[1][0] + twoDArray[1][1] + twoDArray[1][2]));
  23. }
  24. else if(input == 2) {
  25. System.out.println(twoDArray[2][0] + " + " + twoDArray[2][1] + " + " + twoDArray[2][2] + " = " + (twoDArray[2][0] + twoDArray[2][1] + twoDArray[2][2]));
  26. }
  27. else {
  28. System.out.println("0, 1 or 2, it's not hard!");
  29. }
  30. }
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement