
Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Community
Ask the community for help and clear up your study doubts
Discover the best universities in your country according to Docsity users
Free resources
Download our free guides on studying techniques, anxiety management strategies, and thesis advice from Docsity tutors
This java program generates five random numbers and removes the corresponding letters from an arraylist. The user is then asked to input a word in caps, and the program checks if all the characters in the word are present in the arraylist. If so, it displays a message confirming that all characters are present. Otherwise, it displays a message indicating that some characters are missing.
Typology: Exercises
1 / 1
This page cannot be seen from the preview
Don't miss anything!
package alphabet;
import java.util.ArrayList; import java.util.Random; import javax.swing.JOptionPane;
public class Main {
public static void main(String[] args) { Random generator = new Random();
ArrayList letters = new ArrayList(); for (char c='A'; c<'Z'; c++) letters.add(c);
for(int i = 0; i < 5; i++) { int x = 25; int r = generator.nextInt(x); System.out.println("The random numbers are: "+ r); x--; letters.remove(r); }
String word = JOptionPane.showInputDialog("Please Enter Word in CAPS: ");
String message = "i have all characters ";
System.out.println("The word is: "+ word);
for(int i = 0; i < word.length(); i++) { if (letters.contains(word.substring(i))) { JOptionPane.showMessageDialog(null, message); break; } else JOptionPane.showMessageDialog(null, message = "i dont have all characters "); break; } }