Advertisement
smgr

Metódusok - Dórinak

Jan 6th, 2013
39
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.01 KB | None | 0 0
  1. public class program {
  2.     public static void main(String [] args){
  3.        
  4.         int [] szamok = {45,65,65,2,354,5,4,2423,3,4,5,4,2,43,3,25,4,6,57,3};
  5.         String [] nevek = {"András" ,"Emíl" ,"Béla" ,"Láma" ,"Ilona" ,"Béna" ,"Zsombor" ,"Anasztázia"};
  6.        
  7.         intRendezes(szamok);
  8.         stringRendezes(nevek);
  9.        
  10.         for(int x:szamok)
  11.             System.out.print(x + " ");
  12.         System.out.println();
  13.  
  14.         for(String y:nevek)
  15.             System.out.print(y + " ");
  16.         System.out.println();
  17.     }
  18. }
  19.    
  20.     static int[] intRendezes(int [] tomb){
  21.         for(int i=0; i<tomb.length-1; i++){
  22.             for(int j=0; j<tomb.length-1; j++){
  23.                 if(tomb[j] > tomb[j+1]){
  24.                     int tmp = tomb[j];
  25.                     tomb[j] = tomb[j+1];
  26.                     tomb[j+1] = tmp;
  27.                 }
  28.             }
  29.         }
  30.         return tomb;
  31.     }
  32.    
  33.    
  34.     static String[] stringRendezes(String [] args){
  35.         for(int i=0; i<args.length-1; i++){
  36.             for(int j=0; j<args.length-1; j++){
  37.                 if(args[j].compareTo(args[j+1]) >= 0){
  38.                     String tmp = args[j];
  39.                     args[j] = args[j+1];
  40.                     args[j+1] = tmp;
  41.                 }
  42.             }
  43.         }
  44.         return args;
  45.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement