Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- /* ==================================================
- Chapter 2: Syntax section C- Arrays
- Ex6: Repeated char in array
- ===================================================
- */
- public class MyProgram {
- public static void main(String[] args) {
- //variables
- final int SIZE=10;
- char arr[]=new char[SIZE];
- Scanner s=new Scanner(System.in);
- char c;
- int counter=0;
- //user input
- System.out.println("Enter 1 char: ");
- c=s.next().charAt(0);
- System.out.println("Enter 10 Characters: ");
- for(int i=0;i<arr.length;i++){
- arr[i]=s.next().charAt(0);
- if(c==arr[i])
- counter++; //if char has same value inc counter
- }
- //display char accurence
- System.out.println(c+": "+counter+" times");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment