Code
/// Name: Afaf Nabeeha
/// Period: 7
/// Program Name: Randomness
/// File Name: Randomness.java
/// Date Finished: 11/26/2015 public class Randomness
import java.util.Random;
public class Randomness
{
public static void main( String[] args )
{
Random r = new Random();
int x = 1 + r.nextInt(10);
System.out.println( "My random number is " + x );
System.out.println( "Here are some numbers from 1 to 5!" );
System.out.print( 3 + r.nextInt(5) + " " );
System.out.print( 3 + r.nextInt(5) + " " );
System.out.print( 3 + r.nextInt(5) + " " );
System.out.print( 3 + r.nextInt(5) + " " );
System.out.print( 3 + r.nextInt(5) + " " );
System.out.print( 3 + r.nextInt(5) + " " );
System.out.println();
//adds 3 from zero and picks number in interval of [3,7]
System.out.println( "Here are some numbers from 1 to 100!" );
System.out.print( 1 + r.nextInt(100) + "\t" );
System.out.print( 1 + r.nextInt(100) + "\t" );
System.out.print( 1 + r.nextInt(100) + "\t" );
System.out.print( 1 + r.nextInt(100) + "\t" );
System.out.print( 1 + r.nextInt(100) + "\t" );
System.out.print( 1 + r.nextInt(100) + "\t" );
System.out.println();
int number1 = 1 + r.nextInt(10);
int number2 = 1 + r.nextInt(10);
if ( number1 == number2 )
{
System.out.println( "The random numbers were the same! Wierd." );
}
if ( number1 != number2 )
{
System.out.println( "The random numbers were different! Not too suprising, actually." );
}
}
}
Picture of the output