Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Test1 {
- public static void main (String []args){
- Scanner sc = new Scanner(System.in);
- System.out.println("Bitte geben Sie Ihren Text ein:");
- String s = sc.nextLine();
- System.out.println("Bitte geben sie den zu überprüfenden Buchstaben an:");
- String s2 = sc.nextLine();
- char a = s2.charAt(0);
- anzahlpruefen(s,a);
- }
- public static int anzahlpruefen(String s, char a){
- int c=0;
- for(int i =0; i<s.length();i++){
- if(s.charAt(i) ==a){System.out.println("Der Buchstabe an " +i+"ter Stelle ist ein "+a+"."); c++;}
- else{ System.out.println("Der Buchstabe an " +i+"ter Stelle ist kein " +a+".");}
- if (i== s.length()-1){System.out.println("Es war(en) "+c+" " +a+" in Ihrem Text.");}
- }
- return c;}
- }
Add Comment
Please, Sign In to add comment