piglatin


SUBMITTED BY: Guest

DATE: Dec. 25, 2013, 8:06 a.m.

FORMAT: Java

SIZE: 1.7 kB

HITS: 1269

  1. import java.util.*;
  2. public class PigLatin
  3. {
  4. String txt;
  5. int len;
  6. PigLatin()
  7. {
  8. txt="";
  9. len=0;
  10. }
  11. void readstring()
  12. {
  13. Scanner sc=new Scanner(System.in);
  14. System.out.print("\n \tEnter The word in UPPER CASE \n \t");
  15. txt=sc.nextLine();
  16. txt=txt.toUpperCase();
  17. len=txt.length();
  18. convert();
  19. }
  20. void convert()
  21. {
  22. for(int i=0; i<len; i++)
  23. {
  24. if(txt.charAt(i)=='A'||txt.charAt(i)=='E'||txt.charAt(i)=='I'||txt.charAt(i)=='O'||txt.charAt(i)=='U')
  25. {
  26. System.out.println("\n \t The Piglatin Equivalent of the given word is : ");
  27. String sub1=txt.substring(0, i);
  28. String sub=txt.substring(i, (len));
  29. System.out.println("\n \t "+sub+""+sub1+"AY");
  30. break;
  31. }
  32. }
  33. consonents();
  34. }
  35. void consonents()
  36. {
  37. int flag=len;
  38. System.out.println("\n \t The Number of consonents in the given word are : ");
  39. for(int i=0; i<len; i++)
  40. {
  41. if(txt.charAt(i)=='A'||txt.charAt(i)=='E'||txt.charAt(i)=='I'||txt.charAt(i)=='O'||txt.charAt(i)=='U')
  42. {
  43. flag--;
  44. }
  45. }
  46. System.out.println("\n \t "+flag);
  47. }
  48. public static void main(String[] args)
  49. {
  50. PigLatin obj=new PigLatin();
  51. obj.readstring();
  52. }
  53. }

comments powered by Disqus