Guest User

Untitled

a guest
Nov 23rd, 2017
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.79 KB | None | 0 0
  1. // Using isUpperCase() to check whether name or any string entered by user is uppercase or not.
  2. import java.util.Scanner;
  3. class test
  4. {
  5. public static void main(String ar[])
  6. {
  7. Scanner sc=new Scanner(System.in);
  8. System.out.println("Enter any string:");
  9. String name = sc.nextLine();
  10. // extract each character from name by charAt() method.
  11. for(int i=0;i<name.length();i++)
  12. {
  13. char ch = name.charAt(i); // get the 0th character, 1st character and so on..
  14. // if ch is a uppercase character or not
  15. if(Character.isUpperCase(ch))
  16. {
  17. System.out.println("Uppercase character: "+ ch);
  18. }
  19. else
  20. {
  21. System.out.println("Non-Uppercase character: "+ ch);
  22. }
  23. }
  24. }
  25. }
  26. /* OUTPUT:
  27. Enter any string:
  28. JaVA
  29. Uppercase character: J
  30. Non-Uppercase character: a
  31. Uppercase character: V
  32. Uppercase character: A
  33. */
Add Comment
Please, Sign In to add comment