aspose file tools*
The moose likes Beginning Java and the fly likes sort number Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "sort number" Watch "sort number" New topic
Author

sort number

Wiil Bari
Greenhorn

Joined: Sep 20, 2002
Posts: 1
I have a question regarding a sorting number, I can't figured out to make prompt users for the number and search.
here is my code:
import java.awt.*;
import java.io.*;
import java.lang.*;
import java.util.*;
import java.text.*;
public class Sor {
public static void sort(float[] nums) {

float finput ;
String inputline = " 67.000";
finput = Float.valueOf(inputline).floatValue();
NumberFormat nf = NumberFormat.getNumberInstance();
String numberout;
for(int i = 0; i < nums.length; i++) {
numberout = nf.format(nums[i]);
System.out.println(numberout);
}
for(int i = 0; i < nums.length; i++) {
int min = i;
for(int j = i; j < nums.length; j++) {
if (nums[j] < nums[min]) min = j;
}
float tmp;
tmp = nums[i];
nums[i] = nums[min];
nums[min] = tmp;
}
for(int i = 0; i < nums.length; i++) {
numberout = nf.format(nums[i]);
System.out.println(numberout);
}

}
public static void search( float[] nums) {

float x = 1;
BufferedReader in=new BufferedReader(new InputStreamReader(System.in));
System.out.print("Enter float number");
try{
String line = in.readLine();
x = Float.valueOf(line).floatValue();
}
catch(Exception e){}
NumberFormat nf = NumberFormat.getNumberInstance();
String numstring;
for(int i = 0, j = 1; j != 1; i++) {
if (x > nums[i] ) {
if( i == 0 ){
numstring = nf.format(nums[i]);
System.out.println(numstring);
}
else {
numstring = nf.format(nums[i]);
System.out.println( numstring ) ;
numstring = nf.format(nums[i - 1]);
System.out.println( numstring ) ;

}
j =0;
}
if ( i == nums.length ) {
numstring = nf.format(nums[i]);
System.out.println( numstring ) ;
j = 0;
}

//String line;

}

}

public static void main(String[] args) {

float[] nums = new float[10];

for(int i = 0; i < nums.length; i++)
nums[i] = (float)Math.random() * 100;
sort(nums);

search(nums);
//for(int i = 0; i < nums.length; i++)
//System.out.println(nums[i]);

}
}
I believe my search and prompt part is not working and I need your help.
William Barnes
Ranch Hand

Joined: Mar 16, 2001
Posts: 986

Using the "code" tags would help you get a response.


Please ignore post, I have no idea what I am talking about.
Marilyn de Queiroz
Sheriff

Joined: Jul 22, 2000
Posts: 9046
    
  10
Originally posted by Wiil Bari:
I have a question regarding a sorting number, I can't figured out to make prompt users for the number and search.
here is my code:


I believe my search and prompt part is not working and I need your help.


JavaBeginnersFaq
"Yesterday is history, tomorrow is a mystery, and today is a gift; that's why they call it the present." Eleanor Roosevelt
William Barnes
Ranch Hand

Joined: Mar 16, 2001
Posts: 986

Ok, so your code does the sort correctly. After adding a line break between printing out the original numbers and the sorted numbers I was able to see that.
So what do you want to do now?
William Barnes
Ranch Hand

Joined: Mar 16, 2001
Posts: 986

Thanks for the formatted repost Marilyn.
William Barnes
Ranch Hand

Joined: Mar 16, 2001
Posts: 986

I think that this line might be a problem:
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
Wiil, are you aware of the java.util.Arrays class?


The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: sort number