Advertisement
shlomibergic

assignment 9

May 29th, 2019
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.82 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Main {
  4.  
  5. public static void main(String[] args) {
  6. Scanner s =new Scanner(System.in);
  7. char arr[]=new char[5]; // creating array
  8. int counter=0;
  9. System.out.println("please enter five values"); //telling user what to insert
  10. for(int i=0;i<5;i++)// receiving data from user
  11. {
  12. arr[i]=s.next().charAt(0);//data to array arr
  13. }
  14. for(int i=1;i<5;i++) {
  15. if (arr[0] == arr[i]) { //checking if value is equal
  16. counter++;
  17. }
  18. }
  19. if (counter==4)
  20. {
  21. System.out.println("all the same");//if equal
  22. }
  23. else
  24. {
  25. System.out.println("not the same");// if not equal
  26. }
  27. }
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement