10-09-2013

posted Oct 9, 2013, 11:00 AM by Samuel Konstantinovich   [ updated Oct 9, 2013, 11:00 AM ]
Quiz!

While loops:

while ( boolean_expression ){
    //execute these
    //statements when
    //the boolean is true
}


examples:

int i=0;
while(i<10){
    System.out.println(i);
    i=i+1;
}
System.out.println(i);


Coin c = new Coin();
while(c.isHeads() ){
    System.out.println(c.isHeads() );
    c.flip();
}
System.out.println(c.isHeads());


Assignment: (Complete at home)
1. Generate 100 random integers from 1-999 inclusive. Print both the largest and smallest of all of the numbers that were generated.
2. Make random integers form 1-999 until both a 1 and a 999 are created. Print how many numbers had to be generated. 

Comments