SHARE
TWEET

Untitled

a guest May 19th, 2017 41 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Random Number Program
  2. //CS211 HW1 program 11
  3. //Prof. Craig Niiyama Date: 04-10-10
  4.  
  5.  
  6. package edu.bellevuecollege.css211.random;
  7.  
  8. import java.io.IOException;
  9. import java.io.InputStream;
  10.  
  11.  
  12. public class random {
  13.    
  14.    
  15.     public static int randomNumber(int seed)
  16.     {
  17.      return  (40 * seed + 3641) % 729;
  18.     }
  19.  
  20.     /**
  21.      * @param args
  22.      * @throws IOException
  23.      */
  24.     public static void main(String[] args) throws IOException {
  25.         // TODO Auto-generated method stub
  26.        
  27.        
  28.        
  29.         //program welcome message for user
  30.         // prompt user for first number input
  31.         System.out.println("Welcome to random number generator. ");
  32.         System.out.println("Please enter the first number to generate: ");
  33.         int seed = System.in.read();
  34.        
  35.         seed = randomNumber(seed);
  36.    
  37.        
  38.         //calculate the random integers
  39.         // output the first random number
  40.    
  41.         System.out.println("This is your first random number:" + seed);
  42.        
  43.        
  44.        
  45.         //prompt user to continue of exit program
  46.         // outputs the next random number
  47.         System.out.println("Would you like to see the next number (y,n): ");
  48.         char key = (char)System.in.read();
  49.         if (key == 'y'){
  50.        
  51.             seed = randomNumber(seed);
  52.             System.out.println("Next random number is:" + seed);
  53.                        }
  54.             else {
  55.            
  56.                 System.out.println("Goodbye.");
  57.             }
  58.         }
  59.  
  60.  
  61.        
  62.     }
RAW Paste Data
Top