Monday, October 10, 2011

WALKTHROUGH:TNB Java Tut 26-Random Number Generator[VIDEO & SOURCE CODE]]

This is a full walkthrough of Java Tutorial 26 by TheNewBoston. Each walkthrough includes:
  • Embedded Video Tutorial
  • Text Transcript of the tutorial broken down into steps.
  • Source code
If you found this walkthrough helpful and want to see more of them please leave a comment and let me know.Im trying alot of new things and still trying to get a feel for what people want more of.You're feedback counts around here!!!



Step 1.Import the Random package
 import java.util.Random;  

Step 2. Declare a new Random variable and name it "dice"
 Random dice=new Random();  

Step 3. Declare a int variable and name it "number"
 int number;  

Step 4. Create a "for" loop that will loop through 10 times before stopping.

 for(int counter =0;counter<10;counter++){  
 }  

Step 5. Inside the for loop:
  • Set the number var to equal a random number between 1-6
  •   number=1+dice.nextInt(6);  
    
  •  Print the random number variable + a space (" ")
  •   System.out.println(number +" ");  
    
End of Tutorial

 TNB Java Tut 26 Complete Source Code 

 import java.util.Random;  
 class TNBjtut26{  
  public static void main(String[] args){  
 Random dice=new Random();  
 int number;  
 for(int counter =0;counter<10;counter++){  
  number=1+dice.nextInt(6);  
  System.out.println(number +" ");  
 }  
    }  
 }  

1 comment:

Post a Comment

 
;