1. Piglatin String:- Piglatin is a language, in which any consonant at the beginning of a word are placed at the end, followed by -ay; for example cathedral becomes ATHEDRALCAY while London becomes ONDONLAY. 

    class piglatin{
    public static void main(String s){
    int l=s.length();
    int i=0;
    for(i=0;i<l;i++){
    char c=s.charAt(i);
    if(c==’a’||c==’e’||c==’i’||c==’o’||c==’u’){

    break;
    }
    }
    String str=s.substring(0,(i));
    String st=s.substring(i);
    String st1=st.concat(str);
    st1=st1.concat(“ay”);
    System.out.println(st1);
    }
    }

    2. Frequency of characters:- This program will take a sentence from the user and print the frequency of each alphabet.

import java.util.*;
class frequency_of_characters{
public static void main(){
Scanner ob=new Scanner(System.in);
System.out.println(“Enter a String”);
String str=ob.nextLine();
str=str.toUpperCase();
System.out.println(“Frequency of characters in the string \n”);
int l=str.length();
int f=0;
for(int i=65;i<=90;i++){
char ch=(char)i;
for(int j=0;j<l;j++){
if(str.charAt(j)==ch){
f++;
}
}
if(f!=0){
System.out.println(ch+” \t”+f);
}
f=0;
}
}
}

output:-

Enter a string

Life is fun

Life is fun

Frequency of characters in the string
E 1

F 2

I 2

L 1

N 1

S 1

U 1

3. Anagrams:-

An anagram is a word or phrase formed by rearranging the letters of a different word or phrase.(For example TOP and POT are anagram words, because the letters are same, arranged in different way)

import java.util.*;

class anagram{
public static void main(){
Scanner sc=new Scanner(System.in);
System.out.println(“Enter two strings”);
String s1=sc.nextLine();
String s2=sc.nextLine();
s1=s1.toUpperCase();
s2=s2.toUpperCase();
char ch1,ch2;
int n1=0,n2=0,sum1=0,sum2=0;
for(int i=0;i<s1.length();i++){
if(s1.charAt(i)!=’ ‘){
ch1=s1.charAt(i);
n1=(int)ch1;
sum1+=n1;
}
}
for(int i=0;i<s2.length();i++){
if(s2.charAt(i)!=’ ‘){
ch2=s2.charAt(i);
n2=(int)ch2;
sum2+=n2;
}
}
if(sum1==sum2){
System.out.println(“They are anagrams.”);
}
else{
System.out.println(“Not anagrams.”);
}
}
}

Output:-

Enter two strings
CAT
TAC
They are anagrams.
Enter two strings
TAP
POT
Not anagrams.

2 COMMENTS

LEAVE A REPLY

Please enter your comment!
Please enter your name here