Ayuda con numeros aleatorios
Hola tengo este codigo:
import java.io.*;
import java.util.Random;
import java.lang.Math;
public class PruebaRandoms{
double x;
//Random rnd=new Random();
public void main( String args[ ] ) throws IOException {
x=0;
//for (int i = 0; i < 10; i++) {
x =Math.random();//rnd.nextDouble();
System.out.println(x);
//}
}
}
lo compila bien pero al ejecutarlo me da este error
Exception in thread "main" java.lang.NoSouchError: main
import java.io.*;
import java.util.Random;
import java.lang.Math;
public class PruebaRandoms{
double x;
//Random rnd=new Random();
public void main( String args[ ] ) throws IOException {
x=0;
//for (int i = 0; i < 10; i++) {
x =Math.random();//rnd.nextDouble();
System.out.println(x);
//}
}
}
lo compila bien pero al ejecutarlo me da este error
Exception in thread "main" java.lang.NoSouchError: main
Eres tonto o novato, O estas dopado?
TE FALTA EL STATIC
esto es como el padree nuestro
public satic void main( String[] Args )
solo pon el static y YA!
ya lo probe y la salida fue: 0.6057693266505183
Aqui esta el codigo ya corregido
import java.io.*;
import java.util.Random;
import java.lang.Math;
public class pruebaRandoms
{
//Random rnd=new Random();
public static void main( String args[ ] ) {
double x;
x=0;
//for (int i = 0; i < 10; i++) {
x =Math.random();//rnd.nextDouble();
System.out.println(x);
//}
}
Otra observacion: ESTAS PROGRAMANDO BAJO EL PARADIGMA ORIENTADO A OBJETOS!!!! No hagas eso. Estas matando horas de trabajo de los creadores de java. Te mando tambien el codigo optimo:
import java.io.*;
import java.util.Random;
import java.lang.Math;
public class pruebaRandoms
{
double x;
//Constructor
public pruebaRandoms()
{
x=0;
}
public void aleatoriza()
{
for (int i = 0; i < 10; i++)
{
x =Math.random();
System.out.println(x);
}
}
public static void main( String args[ ] )
{
pruebaRandoms pr = new pruebaRandoms();
pr.aleatoriza();
}
}
TE FALTA EL STATIC
esto es como el padree nuestro
public satic void main( String[] Args )
solo pon el static y YA!
ya lo probe y la salida fue: 0.6057693266505183
Aqui esta el codigo ya corregido
import java.io.*;
import java.util.Random;
import java.lang.Math;
public class pruebaRandoms
{
//Random rnd=new Random();
public static void main( String args[ ] ) {
double x;
x=0;
//for (int i = 0; i < 10; i++) {
x =Math.random();//rnd.nextDouble();
System.out.println(x);
//}
}
Otra observacion: ESTAS PROGRAMANDO BAJO EL PARADIGMA ORIENTADO A OBJETOS!!!! No hagas eso. Estas matando horas de trabajo de los creadores de java. Te mando tambien el codigo optimo:
import java.io.*;
import java.util.Random;
import java.lang.Math;
public class pruebaRandoms
{
double x;
//Constructor
public pruebaRandoms()
{
x=0;
}
public void aleatoriza()
{
for (int i = 0; i < 10; i++)
{
x =Math.random();
System.out.println(x);
}
}
public static void main( String args[ ] )
{
pruebaRandoms pr = new pruebaRandoms();
pr.aleatoriza();
}
}
