SHARE
TWEET

total char - targil 1

a guest Aug 18th, 2019 89 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import java.util.Scanner;
  2.  
  3. public class MyArr {
  4.     public static void main(String[] args) {
  5.         Scanner scanner = new Scanner(System.in);
  6.         char[] myChar = new char[4];
  7.         char singleChar;
  8.         int totalChar = 0;
  9.  
  10.         System.out.println("enter "+myChar.length+" chars:");
  11.         for (int counter = 0; counter < myChar.length; counter += 1) {
  12.             myChar[counter] = scanner.next().charAt(0);
  13.         }
  14.  
  15.         System.out.println("Enter char to look for:");
  16.         singleChar = scanner.next().charAt(0);
  17.  
  18.         for (char item:myChar){
  19.             if (item==singleChar){
  20.                 totalChar+=1;
  21.             }
  22.         }
  23.         System.out.println("total char "+singleChar+" appread: "+totalChar);
  24.     }
  25. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top