[go: up one dir, main page]

0% found this document useful (0 votes)
22 views16 pages

StringsQ1 11

The document contains multiple Java programs that perform various string manipulations, including checking for palindromes, counting character frequencies, converting strings to Pig Latin, and modifying string cases. Each program is structured with input reading, processing logic, and output display. The examples illustrate different string operations and transformations based on user input.

Uploaded by

dakshbhardwajjjj
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views16 pages

StringsQ1 11

The document contains multiple Java programs that perform various string manipulations, including checking for palindromes, counting character frequencies, converting strings to Pig Latin, and modifying string cases. Each program is structured with input reading, processing logic, and output display. The examples illustrate different string operations and transformations based on user input.

Uploaded by

dakshbhardwajjjj
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 16

//pallindrome

import java.io.*;
class SQ1
{
public static void main(String[] args)throws IOException
{
String str;
String rev="";
int l;

InputStreamReader I = new InputStreamReader(System.in);


BufferedReader br = new BufferedReader(I);
System.out.println("Enter the string/name");
str=br.readLine();

l=str.length();
for(int i=l-1; i>=0; i--)
{
rev=rev+str.charAt(i);
}
System.out.println(rev);

if(rev.equals(str))
{
System.out.println("PALLINDROME");
}
else
{
System.out.println("NOT");
}

}
}

//Read Only Memory = ROM

import java.io.*;
public class SQ2
{
public static void main(String[] args)throws IOException
{
String str;
int l;

InputStreamReader I = new InputStreamReader(System.in);


BufferedReader br= new BufferedReader(I);
System.out.println("Enter the string/name");
str=br.readLine();

str=str.trim();
str=' '+str;
l=str.length();
for(int i=0; i<l; i++)
{
if(str.charAt(i)==' ')
{
System.out.print(str.charAt(i+1));
}
}

}
}

//RAJA RAM MOHAN ROY = R.R.M. ROY

import java.io.*;
public class SQ3
{
public static void main(String args[])throws IOException
{
String str;
int pos=0;

InputStreamReader I = new InputStreamReader(System.in);


BufferedReader br =new BufferedReader(I);
System.out.println("Enter the string:");
str=br.readLine();

str=str.trim();
str=' '+str;
pos=str.lastIndexOf(' ');
for(int i=0; i<pos; i++)
{
if(str.charAt(i)==' ')
{
System.out.print(str.charAt(i+1)+".");
}
}
System.out.print(str.substring(pos+1));
}
}

//COMPUTER HARDWARE
// A-2, C-1, D-1, E-2, H-1, M-1, O-1, P-1, R-3, T-1, U-1, W-1

import java.io.*;
public class SQ4
{
public static void main(String args[])throws IOException
{
String str;
int l;
int c=0;

InputStreamReader I = new InputStreamReader(System.in);


BufferedReader br = new BufferedReader(I);
System.out.println("Enter the string:");
str=br.readLine().toUpperCase();

l=str.length();
for(int i=65; i<=90; i++)
{
for(int j=0; j<l; j++)
{
if(str.charAt(j)==i)
{
c++;
}

}
if(c>0)
{
System.out.println(c);
}
c=0;
}
}

//Input: Aman Kumar Sharma


//Output: Aman-4, Kumar-5, Sharma-6
import java.io.*;
class SQ5
{
public static void main(String args[])throws IOException
{
String str;
int l;
String w="";

InputStreamReader I = new InputStreamReader(System.in);


BufferedReader br = new BufferedReader(I);
System.out.println("Enter the string");
str = br.readLine().trim();

str=str+' ';
l=str.length();

System.out.println("**************************");
for(int i=0; i<l; i++)
{
while(str.charAt(i)!=' ')
{
w=w+str.charAt(i);
i++;
}
int l2=w.length();
System.out.println(w+"-"+l2);
w="";
}
}
}

//string => array


//Example: Superman is the most powerful.

import java.io.*;
public class SQ6
{
public static void main(String[] args)throws IOException
{
String str;
int l;
int c=0;

InputStreamReader I = new InputStreamReader(System.in);


BufferedReader br= new BufferedReader(I);
System.out.println("Enter the string:");
str=br.readLine().toLowerCase().trim();

str=str+' ';
l=str.length();
for(int i=0; i<l; i++)
{
if(str.charAt(i)==' ')
{
c++;
}
}

System.out.println("*******************");
System.out.println("COUNT OF SPACE: "+ c);

String word[]= new String[c];


String w="";
int c1=0;
for(int i=0; i<l; i++)
{
while(str.charAt(i)!=' ')
{
w=w+str.charAt(i);
i++;
}
word[c1++]=w;
w="";
}

System.out.println("*******************");
for(int i=0; i<c; i++)
{
System.out.println(word[i]);
}
}
}

//input: EXaM => output: EMXa

import java.io.*;
public class SQ7
{
public static void main(String args[])throws IOException
{
String str;
int l;
int x=65;

InputStreamReader I= new InputStreamReader(System.in);


BufferedReader br = new BufferedReader(I);
System.out.println("Enter the pure string:");
str=br.readLine();

l=str.length();

for(int i=x; i<=(x+25); i++)


{
for(int j=0; j<l; j++)
{
if(str.charAt(j)==i)
{
System.out.print(str.charAt(j));
}
}
if(i==90)
{
x=97;
}
}
}
}

//Piglatin = London => ONDONLAY

import java.io.*;
public class SQ8
{
public static void main(String[] args)throws IOException
{
String str;
int l;
String S1="";

InputStreamReader I= new InputStreamReader(System.in);


BufferedReader br = new BufferedReader(I);
System.out.println("Enter the pure string:");
str=br.readLine().toUpperCase();
l=str.length();
for(int i=0; i<l; i++)
{
if(str.charAt(i)=='A'||str.charAt(i)=='E'||str.charAt(i)=='I'||str.charAt(i)=
='O'||str.charAt(i)=='U' )
{
S1= str.substring(i)+str.substring(0,i)+"AY";
System.out.println(S1);
break;
}
}

}
}

//"The quick brown fox jumps over the lazy dog" => user: The '2times'

import java.io.*;
public class SQ9
{
public static void main(String args[])throws IOException
{
String str="The quick brown fox jumps over the lazy dog";
str=str+' ';
int l = str.length();
String x;
int c=0;

InputStreamReader I = new InputStreamReader(System.in);


BufferedReader br = new BufferedReader(I);
System.out.println("Enter the word which want a freq.?");
x=br.readLine().trim();

for(int i=0; i<l; i++)


{
if(str.charAt(i)==' ')
{
c++;
}
}
System.out.println("*********************");
System.out.println("Count:"+ c);

String arr_words[]= new String[c];


String w="";
int c1=0;

for(int i=0; i<l; i++)


{
while(str.charAt(i)!=' ')
{
w=w+str.charAt(i);
i++;
}
arr_words[c1++]=w;
w="";
}

System.out.println("*********************");
for(int i=0; i<c; i++)
{
System.out.println(arr_words[i]);
}

int c2=0;
for(int i=0; i<c; i++)
{
if(arr_words[i].equalsIgnoreCase(x))
{
c2++;
}
}
System.out.println("*********************");
System.out.println("Freq: "+ c2);

}
}

//Computer Applications = Bnlotsdq Zookhbzshnmr


// B/b=> A/a, C/c=>B/b, Z/z=>Y/y, A/a=>Z/z

import java.io.*;
public class SQ10
{
public static void main(String args[])throws IOException
{
String str;
char c=' ';
int l, x;
String str2="";

InputStreamReader I = new InputStreamReader(System.in);


BufferedReader br = new BufferedReader(I);
System.out.println("Enter the String");
str=br.readLine();

l=str.length();
for(int i=0; i<l; i++)
{
c=str.charAt(i);
x=c;
if(x>=66 && x<=90 || x>=98 && x<=122)
{
x=x-1;
}
else if(x==65 || x==97)
{
x=x+25;
}
str2 = str2+(char)x;
}
System.out.println();
System.out.println("Original Str:"+ str);
System.out.println("Modified String:"+ str2);

}
}

//Input: WelComE TO School => Output: wELcOMe to sCHOOL

import java.io.*;
public class SQ11
{
public static void main(String[] args)throws IOException
{
String str;
int l;
int x=0, y=0;

InputStreamReader I = new InputStreamReader(System.in);


BufferedReader br = new BufferedReader(I);
System.out.println("Enter the string");
str=br.readLine().trim();
l=str.length();
for(int i=0; i<l; i++)
{
x=str.charAt(i);
if(x>=65 && x<=90)
{
y=x+32;
}
else
{
y=x-32;
}
System.out.print((char)y);
}
}
}

You might also like