For example the ans I get are all from a range of 0.0 to 0.5 .. how can display out the largest number out ?
12 replies to this topic
#1
Posted 28 April 2011 - 11:14 AM
|
|
|
#2
Posted 28 April 2011 - 02:42 PM
The Math.max() method.
#3
Posted 28 April 2011 - 07:51 PM
Ya but Math.max method is for those who know yr int numbers. But mine reading from a file and pick the largest number out . The number generated will be random in the file. So yea, I can't use Math.max method.
#4
Posted 29 April 2011 - 08:55 AM
Pseudo
int max;
while( file.hasMoreNumbers() ){
int currentNumber = file.nextNumber();
if(max < currentNumber){
max = currentNumber;
}
}
Print: "Max number: " + max;
#5
Posted 29 April 2011 - 09:30 AM
.hasMoreNumbers()
:confused:
#6
Posted 29 April 2011 - 12:35 PM
Well, loop as long the file has more numbers to read...
#7
Posted 29 April 2011 - 09:54 PM
sorry but I cant seem to find
.hasMoreNumbers()
#8
Posted 30 April 2011 - 12:05 AM
#9
Posted 30 April 2011 - 09:46 PM
sound complicated ... hmmm :sleep:
#10
Posted 01 May 2011 - 10:27 AM
public int[] bubbleSort(int[] arr) {
boolean swapped = true;
int j = 0;
int tmp;
while (swapped) {
swapped = false;
j++;
for (int i = 0; i < arr.length - j; i++) {
if (arr[i] > arr[i + 1]) {
tmp = arr[i];
arr[i] = arr[i + 1];
arr[i + 1] = tmp;
swapped = true;
}
}
}
return arr;
}
can bubble sort be used also ?
#11
Posted 01 May 2011 - 12:18 PM
Yes, assuming you've successfully gathered your data and stored it into arr.
Depending on how much data you have, you might reconsider using bubble sort.
Depending on how much data you have, you might reconsider using bubble sort.
#12
Posted 02 May 2011 - 08:06 AM
oh ok ...
I had found this code something in google:
Here's the code :
How can i convert :
I had found this code something in google:
Here's the code :
{
Scanner input=new Scanner(System.in);
System.out.println("Enter positive real numbers: ");
Integer array[]=new Integer[10];
for(int i=0;i<array.length;i++){
array[i]=input.nextInt();
}
System.out.println("Sorted Array in reverse order:");
Arrays.sort(array,Collections.reverseOrder());
for(int i=0;i<array.length;i++){
System.out.println(array[i]);
}
}
As you can see the code requires the user to type in the number ..How can i convert :
for (int j = 0; j < bitSet2.length() - 1 || j < result1.length() - 1; j++) {
if (bitSet2.get(j)) {
writer.append("1");
writer.append(",");
writer.flush();
} else {
writer.append("0");
writer.append(",");
writer.flush();
}
}
nlast = (nlast / (ntarget + nresult - nlast));
float round = Round(nlast, 3);
writer.append(round);
writer.append("\n");
}
As this code, the number(round) would be printed out into the file. How can this code to be modify so that it will be similar to the above ?
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users


Sign In
Create Account


Back to top









