1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Daamn this should work but it doesnt :(

Discussion in 'Java' started by thila, Mar 13, 2011.

  1. thila

    thila New Member

    Joined:
    Mar 13, 2011
    Messages:
    3
    Likes Received:
    0
    Trophy Points:
    0
    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 a moderator: Mar 14, 2011
  2. virxen

    virxen New Member

    Joined:
    Nov 24, 2009
    Messages:
    387
    Likes Received:
    90
    Trophy Points:
    0
    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;
                 }
              }
           }
        }
    }
    
     

Share This Page