Advertisement
Guest User

Untitled

a guest
Dec 7th, 2019
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.67 KB | None | 0 0
  1. public class Esercizio {
  2. public static void main (String [] args){
  3.  
  4. String s1 = new String("abcdefghijklmnopqrstuvwxyz");
  5. char [] rmd = new char [10];
  6.  
  7. for (int i=0;i<10;i++) {
  8. int Lettere = (int) (Math.random()*s1.length()-1);
  9. rmd[i] = s1.charAt(Lettere);
  10. System.out.println(rmd[i]);
  11. }
  12.  
  13. System.out.println("Scrivi il carattere da cercare: ");
  14. char letto = (System.console(). readLine()).charAt(0);
  15.  
  16. int cont = 0;
  17.  
  18. while ((cont<rmd.length-1) && (rmd[cont]!=letto)) {
  19.  
  20. cont++;
  21. }
  22. if (rmd[cont]==letto) {
  23.  
  24. System.out.println("Il carattere e' contenuta nella stringa");
  25. }
  26. else {
  27. System.out.println("Il carattere non e' contenuta nella stringa");
  28. }
  29.  
  30. }
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement