Random Name
/* The program calls a random student name * */ import java.util.Scanner; import java.util.Random; public class RandomName { static Scanner key = new Scanner (System.in); static Random num = new Random(); // Holds an array of student static String student[] = {"Jay", "Joe", "Angie", "Andrew", "Sandra", "Alan"}; public static void main(String[] args) { String choice; System.out.println("What would you like to do?"); do { System.out.println("p--pick and e--exit"); choice = key.nextLine(); if(choice.equals("p") || choice.equals("P")) { int x = num.nextInt(5); System.out.println(student[x]); } else if(choice.equals("e") || choice.equals("E")) { System.out.println("Thank you for using the program!!"); System.exit(0); } else { System.out.println("Invalid Input"); } }while(!choice.equals("e") || !choice.equals("E")); } } Here is the output of the program What would you like to do? p--pick and e--exit p Jay p--pick and e--exit p Joe p--pick and e--exit e Thank you for using the program!!
/* The program calls a random student name * */ import java.util.Scanner; import java.util.Random; public class RandomName { static Scanner key = new Scanner (System.in); static Random num = new Random(); // Holds an array of student static String student[] = {"Jay", "Joe", "Angie", "Andrew", "Sandra", "Alan"}; public static void main(String[] args) { String choice; System.out.println("What would you like to do?"); do { System.out.println("p--pick and e--exit"); choice = key.nextLine(); if(choice.equals("p") || choice.equals("P")) { int x = num.nextInt(5); System.out.println(student[x]); } else if(choice.equals("e") || choice.equals("E")) { System.out.println("Thank you for using the program!!"); System.exit(0); } else { System.out.println("Invalid Input"); } }while(!choice.equals("e") || !choice.equals("E")); } }
Here is the output of the program
What would you like to do? p--pick and e--exit p Jay p--pick and e--exit p Joe p--pick and e--exit e Thank you for using the program!!
< Java > <Home>< Java Programs >