Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package javaapplication3;
- import java.util.Scanner;
- public class JavaApplication3 {
- static Scanner $input = new Scanner(System.in);
- public static void main(String[] args) {
- p("Type the size you want to your map: ");
- int lines = 0;
- boolean done = true;
- while(done){
- lines = l();
- if(lines < 2){
- p("\nYou can't choose this number. Try again!");
- }
- else{
- done = false;
- }
- }
- p("\nGive me your map:");
- int rows = lines;
- int[][] map = new int[lines][rows];
- int counter = 0;
- int count = 0;
- while(counter < lines){
- while(count < rows){
- p("\n Position " + counter + "," + count + ": ");
- map[counter][count] = $input.nextInt();
- count++;
- }
- counter++;
- count = 0;
- }
- int d = 0;
- lines = lines - 1;
- while(lines >= 0){
- d = d + map[lines][lines];
- lines--;
- }
- p("\n\nHere is the plus of your main diagonal: " + d + "\n");
- }
- public static void p(String stri){
- System.out.print(stri);
- }
- public static Integer l(){
- return $input.nextInt();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement