/** Question #38810, Programming, Java | JSP | JSF
* program that displays a random uppercase letter using Math.random() method.
* Your program will prompt user if the program will continue or not using
* JOptionPane.showConfirm() method. A random uppercase letter will be displayed
* if user wants to continue. Document your program as discussed and required in
* the class.
*/
import javax.swing.JOptionPane;
public class Question38810 {
public static char[] letters = getLetters();
public static void main(String[] args) {
do {
System.out.println(letters[(int) (letters.length * Math.random())]);
} while (JOptionPane.showConfirmDialog(null, "continue?") == 0);
}
/**
*
* @return
*/
public static char[] getLetters() {
char[] letters = new char['Z' - 'A' + 1];
for (int i = 0; i < letters.length; i++) {
letters[i] = (char) ('A' + i);
}
return letters;
}
}
Comments