S
stevek
I want to input one or more numbers parameters at program start. One
would be 'number of iterations' = cycles. As my test programs shows I am
stumped at how to assign the string args[0] to a int variable.
public class Random {
public static void main(String[] args) {
System.out.println(" i " + " round-random" + "
round-ramdom");
int cycles = args[0];
for(int i = 0; i < cycles - 1; ++i) {
if(i==0) continue;
System.out.println(i + " " + Math.round(Math.random()*i) + " " +
Math.round(Math.random()*i));
} // for ends
} // main ends
} // Random ends
E:\javastuff\dev\examples>javac Random.java
Random.java:5: incompatible types
found : java.lang.String
required: int
int cycles = args[0];
^
1 error
would be 'number of iterations' = cycles. As my test programs shows I am
stumped at how to assign the string args[0] to a int variable.
public class Random {
public static void main(String[] args) {
System.out.println(" i " + " round-random" + "
round-ramdom");
int cycles = args[0];
for(int i = 0; i < cycles - 1; ++i) {
if(i==0) continue;
System.out.println(i + " " + Math.round(Math.random()*i) + " " +
Math.round(Math.random()*i));
} // for ends
} // main ends
} // Random ends
E:\javastuff\dev\examples>javac Random.java
Random.java:5: incompatible types
found : java.lang.String
required: int
int cycles = args[0];
^
1 error