Hey guys,
I am very new in Java Program. I was trying to sort numbers in the program.
import java.io.*;
/*
* Main.java
*
* Created on May 19, 2007, 10:18 PM
*
/
public class SortNumbers{
public static void sort(double[] nums){
for (int i=0; i<nums.length; i++){
int min =i; // holds the index of the smallest element
for(int j=i; j<nums.length; j++)
{ if (num[j]<num[min])min = j;
}
// Now swap the smallest one with element i.
//This leaves all elements between 0 and i sorted.
double tmp;
tmp =nums;
nums=nums[min];
nums[min]=tmp;
}
}
public class Main {
/** Creates a new instance of Main */
public static void Main(String[] args) {
double[] nums = new double[10];
for(int i=0; i<nums.length; i++)
nums = Math.random() * 100;
sort(nums);
for (int i = 0; i<nums.length; i++)
System.out.println(nums);
}
}
}
I have got a following error:
class, interface or enum expected.
Thanks in advance.
I am very new in Java Program. I was trying to sort numbers in the program.
import java.io.*;
/*
* Main.java
*
* Created on May 19, 2007, 10:18 PM
*
/
public class SortNumbers{
public static void sort(double[] nums){
for (int i=0; i<nums.length; i++){
int min =i; // holds the index of the smallest element
for(int j=i; j<nums.length; j++)
{ if (num[j]<num[min])min = j;
}
// Now swap the smallest one with element i.
//This leaves all elements between 0 and i sorted.
double tmp;
tmp =nums;
nums=nums[min];
nums[min]=tmp;
}
}
public class Main {
/** Creates a new instance of Main */
public static void Main(String[] args) {
double[] nums = new double[10];
for(int i=0; i<nums.length; i++)
nums = Math.random() * 100;
sort(nums);
for (int i = 0; i<nums.length; i++)
System.out.println(nums);
}
}
}
I have got a following error:
class, interface or enum expected.
Thanks in advance.