0% found this document useful (0 votes)
11 views

Java Lec-15 Programs On String.1ebcabf

This document provides code examples for three Java programs that work with strings: 1) A program to find the length of a string. 2) A program to count the vowels in a string. 3) A program to check if a string is a palindrome or not. Each program uses the Scanner class to take user input, and string methods like length(), charAt(), and equals() to manipulate and check properties of the input string.

Uploaded by

Mayur Patil
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)
11 views

Java Lec-15 Programs On String.1ebcabf

This document provides code examples for three Java programs that work with strings: 1) A program to find the length of a string. 2) A program to count the vowels in a string. 3) A program to check if a string is a palindrome or not. Each program uses the Scanner class to take user input, and string methods like length(), charAt(), and equals() to manipulate and check properties of the input string.

Uploaded by

Mayur Patil
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/ 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