Showing posts with label random. Show all posts
Showing posts with label random. Show all posts
Monday, October 10, 2011 1 comments

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 comments

CHALLENGE:Java Tut 30-Array Elements As Counters

The following is a challenge for new developers that have completed:
 Java Tutorial - 30 Array Elements As Counters by theNewBoston
 


B.A.M.F Challenge:
B.A.M.F Challenges & why you want to always at leas try them explained Here:http://bit.ly/ogivqe
Difficulty: 1/2
 Create a java console program using arrays and for loops that simulates a 6 sided die being tossed 1000 times. Then print the amount of times it fell on each side of the die to the console. Your console output should look something like this: 
Face      Frequency
1                182          
2                 220         
3                134          
4                278          
5                169         
6                188          



CHALLENGE!!
(Before starting any of the challenges always declare a class and a main method unless told otherwise)
 Difficulty:★1/2
1.Create a Random variable and name it rand
2.Create a int array that holds 7 int's, name it freq. 
3.Create a for loop that loops 1000 times.Each time it loops it should:
       *++freq[1+rand.nextInt(6)];
4.Below the for loop print a header that reads "Face        Frequency"
5.Create another for loop:
  Start you're "counter" at 1, the loop should continue as long as face is less than the length of the freq array , increment by 1 , each time it loops it should :
                   *Print the index , a few spaces and the value of the index position.(See the example in the                      B.A.M.F example if you're confused.

View the video tutorial: http://bit.ly/nFzFhL 

 
;