Results 1 to 11 of 11
  1. #1
    amalina is offline Member
    Join Date
    Jul 2009
    Posts
    17
    Rep Power
    0

    Exclamation please help me.....please...

    i got an assignment to do..
    the assignment is:
    write a program about sorting a negative to positive number in easy word from small to big number..
    the original number given is:23 45 -234 -456 -2 -4 333 56 35
    the sorted number is:-456 -234 -4 -2 23 35 45 56 333
    please help me to write the syntax or coding using for loop and array condition..
    please help me...
    your help is very2 necessary for me to completing the task..
    thank you..
    reply me as soon as possible..
    Last edited by amalina; 07-21-2009 at 10:24 AM. Reason: left some words

  2. #2
    dswastik is offline Senior Member
    Join Date
    Dec 2008
    Location
    Kolkata
    Posts
    282
    Rep Power
    6

    Default

    I think you should try to do it yourself first. If you face problem we are always here to help you.

  3. #3
    amalina is offline Member
    Join Date
    Jul 2009
    Posts
    17
    Rep Power
    0

    Red face please again

    i have tried to do by myself..
    now there no much time left..
    i have no idea what to do anymore..
    its have come to the end of my critical thinking..
    i cannot find any solution anymore..
    could somebody help me out of this problem..
    plz..
    i need ur help..
    a.s.a.p
    :(

  4. #4
    dswastik is offline Senior Member
    Join Date
    Dec 2008
    Location
    Kolkata
    Posts
    282
    Rep Power
    6

    Default

    Java Code:
    int nums[]={23,45,-234,-456,-2,-4,333,56,35};
    		for (int i = 0; i < nums.length - 1; i++){
    			for (int j = i + 1; j < nums.length; j++){
    				if (nums[i] > nums[j]){
    					int temp = nums[i];
    					nums[i] = nums[j];
    					nums[j] = temp;
    				}
    			}
    		}

  5. #5
    amalina is offline Member
    Join Date
    Jul 2009
    Posts
    17
    Rep Power
    0

    Question i like to have in detail syntax..

    the output have to be like this:
    original number:23 45 -234 -456 -2 -4 333 56 35
    sorted number:-456 -234 -4 -2 23 35 45 56 333
    and the problem with your code is..
    i didn't see any output..
    but its stated build successful..
    with none of the output i wanna see..
    please help me once again..
    i really appreciate ur help...

  6. #6
    dswastik is offline Senior Member
    Join Date
    Dec 2008
    Location
    Kolkata
    Posts
    282
    Rep Power
    6

    Default

    Java Code:
    int nums[]={23,45,-234,-456,-2,-4,333,56,35};
    		for (int i = 0; i < nums.length - 1; i++){
    			for (int j = i + 1; j < nums.length; j++){
    				if (nums[i] > nums[j]){
    					int temp = nums[i];
    					nums[i] = nums[j];
    					nums[j] = temp;
    				}
    			}
    		}
    //you just need to print the array after sorting
    for (int i = 0; i < nums.length; i++){
      System.out.print(nums[x]+" ");
    }

  7. #7
    amalina is offline Member
    Join Date
    Jul 2009
    Posts
    17
    Rep Power
    0

    Question i didnt not understand it well..

    i said i want the output like i show u before..
    it must have display the original and the sorted number...
    its mean there is two line of output...
    is ur code is readable by netbeans software...
    i am so sorry..
    that is y i ask the expert to solve my prob about this...
    very2 sorry..

  8. #8
    dswastik is offline Senior Member
    Join Date
    Dec 2008
    Location
    Kolkata
    Posts
    282
    Rep Power
    6

    Default

    Java Code:
    public static void main(String[] arg){
    		int nums[]={23,45,-234,-456,-2,-4,333,56,35};
    
    		int unsortedNums[]=new int[nums.length];
    
    		//store the original numbers in the array called unsortedNums for displaying later
    		for(int x=0;x<nums.length;x++){
    			unsortedNums[x]=nums[x];
    		}
    
    		//sort the nums array
    		for (int i = 0; i < nums.length - 1; i++){
    			for (int j = i + 1; j < nums.length; j++){
    				if (nums[i] > nums[j]){
    					int temp = nums[i];
    					nums[i] = nums[j];
    					nums[j] = temp;
    				}
    			}
    		}
    		//display the original array i.e. array called unsortedNums
    		System.out.print("Original Numbers:");
    		for(int x=0;x<unsortedNums.length;x++){
    			System.out.print(unsortedNums[x]+" ");
    		}
    
    		//display the sorted array i.e. array called nums
    		System.out.print("\nSorted Numbers:");
    		for(int x=0;x<nums.length;x++){
    			System.out.print(nums[x]+" ");
    		}
    
    		//just to print a blank line
    		System.out.println("");
    	}

  9. #9
    amalina is offline Member
    Join Date
    Jul 2009
    Posts
    17
    Rep Power
    0

    Talking tq damn much...

    without your help..
    i cannot solve the problem...
    thank you...
    very2..
    much...
    i hope you can help me with the..
    upcoming problem..
    about java...
    thank you....

  10. #10
    angryboy's Avatar
    angryboy is offline Senior Member
    Join Date
    Jan 2009
    Posts
    742
    Rep Power
    6

    Default

    hmmm... nice spoonfeeding session going on...
    USE CODE TAGS--> [CODE]...[/CODE]
    Get NotePad++ (free)

  11. #11
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,450
    Rep Power
    19

    Default

    Oh joy. Someone else I'll have to clean up after in a few years time.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •