RcrdBrt

Untitled

Nov 10th, 2014
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.64 KB | None | 0 0
  1. import java.util.Scanner;
  2. public class Es6 {
  3. public static void main(String[] args) {
  4. Scanner kb = new Scanner(System.in);
  5. String stringa = kb.nextLine();
  6. System.out.println("inserisci il carattere che vuoi cercare");
  7. String car = kb.next();
  8. char carattere = car.charAt(0);
  9. // int carattere = (int) car;
  10. int j = 0;
  11. for (int i=0; i<stringa.length();i++) {
  12. if (stringa.charAt(i)==carattere)
  13. j++;
  14. }
  15. if (j!=1)
  16. System.out.println("il carattere che vuoi cercare e' presente " + j + " volte nella stringa");
  17. else System.out.println("il carattere che vuoi cercare e' presente " + j + " volta nella stringa");
  18. }
  19. }
Advertisement
Add Comment
Please, Sign In to add comment