Question #38810

program that displays a random uppercase letter using Math.random() method. Your program will promt 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.
1

Expert's answer

2014-02-05T11:06:01-0500
/** 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;
    }
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!
LATEST TUTORIALS
APPROVED BY CLIENTS