Advertisement
Guill

Algs aula

Aug 12th, 2013
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.18 KB | None | 0 0
  1. package javaapplication3;
  2. import java.util.Scanner;
  3. public class JavaApplication3 {
  4.    
  5.     static Scanner $input = new Scanner(System.in);
  6.    
  7.     public static void main(String[] args){
  8.         sort_arr(args);        
  9.     }
  10.    
  11.     public static void main_diag(String[] args) {
  12.         p("Type the size you want to your map: ");
  13.         int lines = 0;
  14.         boolean done = true;
  15.         while(done){
  16.             lines = l();
  17.             if(lines < 2){
  18.                 p("\nYou can't choose this number. Try again!");
  19.             }
  20.             else{
  21.                 done = false;
  22.             }
  23.         }        
  24.         p("\nGive me your map:\n");
  25.         int rows = lines;
  26.         int[][] map = new int[lines][rows];
  27.         int counter = 0;
  28.         int count = 0;
  29.         while(counter < lines){
  30.             while(count < rows){
  31.                 p("   Position " + counter + "," + count + ": ");
  32.                 map[counter][count] = $input.nextInt();
  33.                 count++;
  34.             }
  35.             counter++;
  36.             count = 0;
  37.         }
  38.         int d = 0;
  39.         lines = lines - 1;
  40.         while(lines >= 0){
  41.             d = d + map[lines][lines];
  42.             lines--;
  43.         }
  44.         p("\n\nHere is the plus of your main diagonal: " + d + "\n");
  45.     }
  46.    
  47.     public static void sort_arr(String[] args){
  48.         p("Enter your array's size:");
  49.         int size = l();
  50.         int[] arr = new int[size];
  51.         p("Enter your Integer array:\n");
  52.         int count = 0;
  53.         while(count < size){
  54.             p("   Position " + count + ": ");
  55.             arr[count] = l();
  56.             count++;
  57.         }    
  58.         int c = 0;
  59.         int[] temp = new int[size];
  60.       while(c <= temp.length){
  61.         count = c;
  62.         int n = arr[c];
  63.         while(count < size){
  64.             if(n < arr[count]){
  65.                 n = arr[count];
  66.                 count = -1;
  67.             }
  68.             count++;
  69.         }
  70.         temp[c] = n;
  71.       }
  72.       p(temp.toString());
  73.        
  74.     }
  75.    
  76.     public static void p(String stri){
  77.         System.out.print(stri);
  78.     }
  79.    
  80.     public static Integer l(){
  81.         return $input.nextInt();
  82.     }
  83. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement