Advertisement
Guest User

Untitled

a guest
Feb 23rd, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.54 KB | None | 0 0
  1.     public static void main(String[] args){
  2.        
  3.         Scanner input = new Scanner(System.in);
  4.         System.out.print("Skriv in en text: ");
  5.         String text = input.nextLine();
  6.         int AntalBokstav = räknaTecken(text, 'a');
  7.         System.out.print("Det finns " + AntalBokstav + " tecken med bokstaven a.");
  8. }
  9.  
  10.  
  11. public static int räknaTecken(String text, char tecken){
  12.     int antal = 0;
  13.     for (int i = 0; i < text.length(); i++) {
  14.         if(text.charAt(i) == tecken)
  15.             antal++;
  16.     }
  17.     return antal;
  18. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement