QUOTE(davedave22 @ 9 Oct, 2008 - 09:26 PM)

Very nice tutorial and thanks for the reply Locke37, got me on the right track with looping. However, i think i am more stuck with using parameters. For example i just wanted to see if i could get the number to be printed out that i had input into a seperate method and nothing came out
CODE
import java.util.*;
import java.lang.Math;
class Random
{
public static void main( String[] args)
{
int snumber;
Scanner scan = new Scanner(System.in);
System.out.print("Enter a value of n: ");
snumber = scan.nextInt();
if (snumber == 0)
{
System.out.println("Thanks for playing, and make it a great day! :)");
System.exit(0);
}
while (100 > snumber || snumber > 500)
{
System.out.println("So sorry. The value must be between 100 and 500 inclusively.");
System.out.print("Enter a value of n: ");
snumber = scan.nextInt();
if (snumber == 0)
{
System.out.println("Thanks for playing, and make it a great day! :)");
System.exit(0);
}
}
}
public void generate(int snumber) {
System.out.println("n is " + snumber);
}
}
I edited my code a little to fix it up towards the specifications i need, but i am confused on using parameters X_X thanks again for the help
Well, I see nothing wrong.
The only thing I see is not an error(at least I don't believe it is), but it's just a little confusing to anybody that reads the code.
When you declare your
generate(int snumber) method...I wouldn't name the parameter
snumber, as there is a variable with the same identifier in your
main method.
I'd change it to this.
java
public void generate(int num)
{
System.out.println("n is " + num);
}
One more thing...you never make a call to the
generate() method. That might affect the outcome of the program.