Download as pdf or txt
Download as pdf or txt
You are on page 1of 3

Course: Java Programming, Prepared By: Atul Kabra, 9422279260

Java Lecture-15 Notes


Topic: Programs On String

1) Write a program to find length of String.


import java.util.*;

class StringLength
{
public static void main(String [] args)
{
Scanner in = new Scanner(System.in);

System.out.println("Enter the string ");


String str = in.nextLine();

int x = str.length();

System.out.println("Length of String = "+x);


}
}

Output:

Course: Java Programming, Info Planet Programming Classes Prepared By: Atul Kabra, 9579460114
Course: Java Programming, Prepared By: Atul Kabra, 9422279260

2) Write a program to count vowel of the string.


import java.util.*;

class StringVowel
{
public static void main(String [] args)
{
Scanner in = new Scanner(System.in);

System.out.println("Enter the string ");


String str = in.nextLine();

int c=0;
for(int i=0;i<str.length();i++)
{
char ch = str.charAt(i);
if(ch=='a'||ch=='e'||ch=='i'||ch=='o'||ch=='u')
c++;
}

System.out.println("Vowels in String = "+c);


}
}

Output:

Course: Java Programming, Info Planet Programming Classes Prepared By: Atul Kabra, 9579460114
Course: Java Programming, Prepared By: Atul Kabra, 9422279260

3) Write a program to find out String is palindrome or not palindrome.


import java.util.*;

class StringPalindrome
{
public static void main(String [] args)
{
Scanner in = new Scanner(System.in);

System.out.println("Enter the string ");


String str = in.nextLine();

String rev="";

for(int i=str.length()-1;i>=0;i--)
{
char ch = str.charAt(i);
rev=rev+ch;
}

if(str.equals(rev))
System.out.println(str+ " is Palindrome String");
else
System.out.println(str+ " is not a Palindrome String");
}
}

Output:

Course: Java Programming, Info Planet Programming Classes Prepared By: Atul Kabra, 9579460114

You might also like