Daamn this should work but it doesnt :(

thila's Avatar, Join Date: Mar 2011
Newbie Member
Code:
import java.io.*;
import java.util.Scanner;

class num
{
    public static void main(String args[])
	{ 
           
            
              for (int i=1;i<=10;i++)
          {
		Scanner input = new Scanner(System.in);
                 int array[]=new int[10]; 
		int array[i] = input.nextInt();
	
          }
        }
    
    void Descending (int array[])
    {
       for(int j=8;j>=0;j--);
       {
           for(int y=0;y<=x;y++)     
           {
               if (array[y]>array[y+1]);
               temp= array[y];
               array[y]=array[y+1];
               array[y+1]=temp;
           }     
       }
    }
        
    
    
    
    
    void Ascending (int array[])
     {
       for(int j=8;j>=0;j--);
       {
          for(int y=0;y<=x;y++)
               
           {
             if (array[y]<array[y+1]);
                 temp= array[y];
               array[y]=array[y+1];
               array[y+1]=temp;
           }
       }
    }
}

Last edited by shabbir; 14Mar2011 at 07:15.. Reason: Code blocks
virxen's Avatar, Join Date: Nov 2009
Pro contributor
try this

Code:
import java.io.*;
import java.util.Scanner;

class num{
    public static void main(String args[])    { 
        int array[]=new int[10];
        for (int i=0;i<10;i++){//arrays starts from 0
            Scanner input = new Scanner(System.in);
            array[i] = input.nextInt();
    
          }
          System.out.println("descending order...");
          Descending(array);
          for (int i=0;i<array.length;i++)
              System.out.print(" "+array[i]+" ");
          System.out.println("");
          System.out.println("ascending order...");
          Ascending(array);
          for (int i=0;i<array.length;i++)
              System.out.print(" "+array[i]+" ");  
          System.out.println("");            
        }
    
    static void Descending (int array[]){
        int temp;
       for(int j=array.length-1;j>0;j--){
           for(int y=0;y<j;y++){
               if (array[y]<array[y+1]){
                       temp= array[y];
                       array[y]=array[y+1];
                       array[y+1]=temp;
                   }     
               }
        }
    }
        
    
    
    
    
   static  void Ascending (int array[]){
        int temp;
       for(int j=array.length-1;j>0;j--){
           for(int y=0;y<j;y++){
             if (array[y]>array[y+1]){
                 temp= array[y];
                    array[y]=array[y+1];
                 array[y+1]=temp;
             }
          }
       }
    }
}