StdRandom, StdOut, Insertion cannot be resolved
12,415
Solution 1
you need to use the following files
http://introcs.cs.princeton.edu/java/stdlib/StdRandom.java.html
http://algs4.cs.princeton.edu/11model/StdOut.java.html
Solution 2
You're definitely missing some imports of non-standard libraries here. If you want to compile and use this code as it is, you should ask your professor where to find the libraries and how to import them.
But if you just want an example of doing approximately what's shown here with standard java libraries, the following might suffice:
import java.util.Arrays;
import java.util.Random;
public class RandomDoubles {
public static void main(String[] args)
{
int N = Integer.parseInt(args[0]);
Double[] a = new Double[N];
Random rand = new Random();
for(int i = 0; i < N; i++)
a[i] = rand.nextDouble();
Arrays.sort(a);
for (int i = 0; i < N; i++)
System.out.println(a[i]);
}
}
Author by
Aleksei Chepovoi
Updated on June 04, 2022Comments
-
Aleksei Chepovoi almost 2 years
This code should implement sorting.
I have 3 errors:
"StdRandom cannot be resolved",
"StdOut cannot be resolved",
"Insertion cannot be resolved".
May be there are some libraries to import?public class randomDoubles { public static void main(String[] args) { int N = Integer.parseInt(args[0]); Double[] a = new Double[N]; for(int i = 0; i < N; i++) a[i] = StdRandom.uniform(); // error: StdRandom cannot be resolved Insertion.sort(a); // error: Insertion cannot be resolved for (int i = 0; i < N; i++) StdOut.println(a[i]); // error: StdOut cannot be resolved } }
-
Atcold about 8 yearsAnd how do you import them?
-
Baimyrza Shamyr almost 8 yearsJust create new files with these contents with names of the classes in the same folder with main file, and it will definitely run.
-
rv1822 over 7 yearsIf you are using DrJava, you can include stdlib.jar in the classpath, Preferences -> Extra Classpath -> Add. Check introcs.cs.princeton.edu/java/stdlib