Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static void main(String[] args){
- Scanner input = new Scanner(System.in);
- System.out.print("Skriv in en text: ");
- String text = input.nextLine();
- int AntalBokstav = räknaTecken(text, 'a');
- System.out.print("Det finns " + AntalBokstav + " tecken med bokstaven a.");
- }
- public static int räknaTecken(String text, char tecken){
- int antal = 0;
- for (int i = 0; i < text.length(); i++) {
- if(text.charAt(i) == tecken)
- antal++;
- }
- return antal;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement