RcrdBrt

Untitled

Nov 10th, 2014
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.59 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. char car = kb.next();
  8. // int carattere =
  9. int j = 0;
  10. for (int i=0; i<stringa.length();i++) {
  11. if (stringa.charAt(i)==car)
  12. j++;
  13. }
  14. if (j!=1)
  15. System.out.println("il carattere che vuoi cercare e' presente " + j + " volte nella stringa");
  16. else System.out.println("il carattere che vuoi cercare e' presente " + j + " volta nella stringa");
  17. }
  18. }
Advertisement
Add Comment
Please, Sign In to add comment