Guest User

Untitled

a guest
Apr 21st, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.91 KB | None | 0 0
  1. import java.util.Scanner;
  2. public class Test1 {
  3.  
  4. public static void main (String []args){
  5.  
  6. Scanner sc = new Scanner(System.in);
  7. System.out.println("Bitte geben Sie Ihren Text ein:");
  8. String s = sc.nextLine();
  9. System.out.println("Bitte geben sie den zu überprüfenden Buchstaben an:");
  10. String s2 = sc.nextLine();
  11. char a = s2.charAt(0);
  12.  
  13. anzahlpruefen(s,a);
  14. }
  15. public static int anzahlpruefen(String s, char a){
  16. int c=0;
  17. for(int i =0; i<s.length();i++){
  18. if(s.charAt(i) ==a){System.out.println("Der Buchstabe an " +i+"ter Stelle ist ein "+a+"."); c++;}
  19. else{ System.out.println("Der Buchstabe an " +i+"ter Stelle ist kein " +a+".");}
  20. if (i== s.length()-1){System.out.println("Es war(en) "+c+" " +a+" in Ihrem Text.");}
  21.  
  22. }
  23. return c;}
  24. }
Add Comment
Please, Sign In to add comment