Advertisement
Guill

java matriz

Aug 7th, 2013
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.35 KB | None | 0 0
  1. package javaapplication3;
  2. import java.util.Scanner;
  3. public class JavaApplication3 {
  4.     static Scanner $input = new Scanner(System.in);
  5.     public static void main(String[] args) {
  6.         p("Type the size you want to your map: ");
  7.         int lines = 0;
  8.         boolean done = true;
  9.         while(done){
  10.             lines = l();
  11.             if(lines < 2){
  12.                 p("\nYou can't choose this number. Try again!");
  13.             }
  14.             else{
  15.                 done = false;
  16.             }
  17.         }        
  18.         p("\nGive me your map:");
  19.         int rows = lines;
  20.         int[][] map = new int[lines][rows];
  21.         int counter = 0;
  22.         int count = 0;
  23.         while(counter < lines){
  24.             while(count < rows){
  25.                 p("\n   Position " + counter + "," + count + ": ");
  26.                 map[counter][count] = $input.nextInt();
  27.                 count++;
  28.             }
  29.             counter++;
  30.             count = 0;
  31.         }
  32.         int d = 0;
  33.         lines = lines - 1;
  34.         while(lines >= 0){
  35.             d = d + map[lines][lines];
  36.             lines--;
  37.         }
  38.         p("\n\nHere is the plus of your main diagonal: " + d + "\n");
  39.     }
  40.    
  41.     public static void p(String stri){
  42.         System.out.print(stri);
  43.     }
  44.    
  45.     public static Integer l(){
  46.         return $input.nextInt();
  47.     }
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement