Assignemnt #78
Code
/// Name: Daniel Nguyen
/// Period: 6
/// Program Name: cwaf Program
/// File Name: cwaf.java
/// Date Finished: 9/9/2015
// it adds 1 to the variable every time it recycles so that the loop eventually stops
// it initializes the variable and makes it ignore it
//
import java.util.Scanner;
import java.util.Random;
public class cwaf
{
public static void main( String[] args )
{
Random rng = new Random();
Scanner keyboard = new Scanner(System.in);
int rng2 = rng.nextInt(10);
System.out.println( "Type in a message, and I'll display it " + rng2 + " times." );
System.out.print( "Message: " );
String message = keyboard.nextLine();
for ( int n = 1 ; n <= rng2 ; n = n+2 )
{
System.out.println( n + ". " + message );
}
}
}
Picture of the output