Advertisement
Guest User

arrays9

a guest
Nov 19th, 2017
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.65 KB | None | 0 0
  1. package arrays9;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class arrays9 {
  6.  
  7.     public static void main(String[] args) {
  8.  
  9.         Scanner s = new Scanner(System.in);
  10.        
  11.         //array
  12.         char[] arr = new char[5];
  13.        
  14.         //input - 5 chars
  15.         System.out.println("Enter 5 chars");
  16.        
  17.         //loop to get 5 chars from user
  18.         for (int i = 0; i < 5; i += 1) {
  19.             arr[i] = s.next().charAt(0);
  20.         }
  21.  
  22.         int yes = 1;
  23.         char ch = arr[0]; //for comparison
  24.         int i = 1;
  25.         while (i < 5) {
  26.             if (ch == arr[i]) //if the same
  27.                 yes += 1;
  28.             i += 1;
  29.         }
  30.        
  31.         //output - if chars are the same
  32.         System.out.println("all chars" + (yes == 5 ? "" : " do not") + " match");
  33.  
  34.     }
  35.  
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement