@ .(dot) gmail com Example: icse2024@gmail.com is a valid gmail id
import java.util.*;
public class Prac
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter gmail id : ");
String s=sc.next();
if(s.endsWith("@gmail.com"))
System.out.println("Valid");
else
System.out.println("Not Valid");
}
}Example : S = "KAPILDEV@83" Output : Number of Digits - 2 Number of Alphabets - 8 Number of Spaces - 0 Number of Special Characters - 1
import java.util.*;
public class Prac
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter a string :");
String s=sc.nextLine();
int digit=0, letter=0, space=0, special=0;
for(int i=0; i<s.length(); i++) {
char ch=s.charAt(i);
if(Character.isDigit(ch))
digit = digit + 1;
else if(Character.isLetter(ch))
letter = letter + 1;
else if(Character.isWhitespace(ch))
space = space + 1;
else
special = special + 1;
}
System.out.println("Number of Alphabets : " +letter);
System.out.println("Number of Digits : " +digit);
System.out.println("Number of Spaces : " +space);
System.out.println("Number of Special Characters : " +special);
}
}
Example : INPUT : WelCoMe_2022 OUTPUT : wELcOmE_2022
import java.util.*;
public class Prac
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter a string :");
String s1=sc.nextLine();
String s2="";
for(int i=0; i<s1.length(); i++) {
char ch=s1.charAt(i);
if(Character.isUpperCase(ch))
ch=Character.toLowerCase(ch);
else if(Character.isLowerCase(ch))
ch=Character.toUpperCase(ch);
s2=s2+ch;
}
System.out.println("Original String is : "+s1);
System.out.println("New String is : "+s2);
}
}
Example : INPUT : India is my country OUTPUT : INDIA IS MY COUNTRY
import java.util.*;
public class Prac
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter a string :");
String s1=sc.nextLine();
s1=s1+' ';
String word="";
for(int i=0; i<s1.length(); i++) {
char ch=s1.charAt(i);
if(ch==' ') {
System.out.println(word);
word="";
}
else {
word=word+ch;
}
}
}
}
Example : INPUT : ADVANCEMENT AND APPLICATION OF INFORMATION TECHNOLOGY ARE EVER CHANGING OUTPUT : Total number of words starting with letter ‘A’ = 4
import java.util.*;
public class Prac
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter a string :");
String s1=sc.nextLine();
s1=s1.toUpperCase()+' ';
String word="";
int count=0;
for(int i=0; i<s1.length(); i++) {
char ch=s1.charAt(i);
if(ch==' ') {
if(word.charAt(0)=='A') {
count++;
}
word="";
}
else {
word=word+ch;
}
}
System.out.println("Total number of words starting with 'A' : "+count);
}
}
Example : INPUT : we are in cyber world OUTPUT : We Are In Cyber World
import java.util.*;
public class Prac
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter a string :");
String s1=sc.nextLine();
s1=' '+s1.toLowerCase();
String s2="";
for(int i=0; i<s1.length(); i++) {
char ch=s1.charAt(i);
if(ch==' ') {
ch=s1.charAt(i+1);
ch=Character.toUpperCase(ch);
s2=s2+' ';
i=i+1;
}
s2=s2+ch;
}
System.out.println("New string : "+s2.trim());
}
}
Example : EXISTENCE, COMIC, WINDOWPalindrome words are those words which read the from left to right and vice-versa.
Example : MALAYALAM, MADAM, LEVEL, ROTATOR, CIVICAll palindromes are special words, but all special words are not palindrome.
import java.util.*;
public class Prac
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter a string :");
String s1=sc.next();
s1=s1.toUpperCase();
int len=s1.length();
String rev="";
for(int i=0; i<s1.length(); i++) {
char ch=s1.charAt(i);
rev=ch+rev;
}
if(s1.equals(rev))
System.out.println("Palindrome String");
else if(s1.charAt(0) == s1.charAt(len-1))
System.out.println("Special Word");
else
System.out.println("Neither Palindrome Nor Special");
}
}
Example : INPUT : C:\Users\admin\Pictures\flower.jpg OUTPUT : Path : C:\Users\admin\Pictures\ File name : flower Extension : jpg
Example : INPUT(1) : London OUTPUT(1) : ONDONLAY INPUT(2) : Olympics OUTPUT(2) : OLYMPICSAY
Example : INPUT : SHE WAS FEEDING THE LITTLE RABBIT WITH AN APPLE OUTPUT : Number of double letter sequences = 4
Sample Input: computer Sample Output: cpmpvtfr
Sample Input: APPLICATIONS Sample Output: Character - Frequency A - 2 P - 2 L - 1 C - 1 T - 1 I - 2 O - 1 N - 1 S - 1