Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Es6 {
- public static void main(String[] args) {
- Scanner kb = new Scanner(System.in);
- String stringa = kb.nextLine();
- System.out.println("inserisci il carattere che vuoi cercare");
- String car = kb.next();
- char carattere = car.charAt(0);
- // int carattere = (int) car;
- int j = 0;
- for (int i=0; i<stringa.length();i++) {
- if (stringa.charAt(i)==carattere)
- j++;
- }
- if (j!=1)
- System.out.println("il carattere che vuoi cercare e' presente " + j + " volte nella stringa");
- else System.out.println("il carattere che vuoi cercare e' presente " + j + " volta nella stringa");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment