for(j=0;j<m;j++)
char ch=x.charAt(j);
if(ch=='a' || ch=='e' || ch=='i' || ch=='o' || ch=='u' || ch=='A' ||
ch=='E' || ch=='I' || ch=='O' || ch=='U')
v++;
System.out.println("Number of Vowels in '"+x+"' is "+v);
x="";
v=0;
}
Output:
Program 7:
Write a program to print the following series:
1, 11, 111, 1111, 11111, 111111,…………………upto n terms
Algorithm:
START
STEP 1: Take the value of n from the user and use a single for loop.
STEP 2: Take two variables whose initial values are 0.
STEP 3: Now calculate the value of the series in one of the variables.
STEP 4: Print the series.
STOP
Source Code:
public class Ser1
public static void main(int n)
int i,a=0,b=0;
for(i=1;i<=n;i++)
b=(10*a)+1;
System.out.print(b+" ,");
a=b;
Output:
Program 8:
Write a program to input a sentence from user and find and print
the words in the string. Then, display the reversed form of each
word.
Algorithm:
START
STEP 1: Input a sentence from the user.
STEP 2: Extract the characters from the string.
STEP 3: Extract the words from the by checking whether the extracted character
is whitespace or not.
STEP 4: Extract the characters from each of the words.
STEP 5: Obtain the reversed form of each word.
Source Code:
import java.util.*;
public class StringManupulation
public static void main(String args[])
Scanner sc= new Scanner(System.in);
System.out.println("Enter a String : ");
String s= sc.nextLine();
int i,n;
String wd="";
n=s.length();
for(i=0;i<n;i++)
char ch= s.charAt(i);
if(ch!=' ' && i<n-1)
wd=wd+ch;
else
if(i==n-1)
wd=wd+ch;
System.out.println("The word in string are : "+wd);
int len=wd.length();
String rev="";
for(int j=len-1;j>=0;j--)
char ch1= wd.charAt(j);
rev=rev+ch1;
System.out.println("Reverse of the word is : "+rev);
wd="";
}
Output:
Program 9:
Write a program to input n number of string in a single-
dimensional array and sort them using Bubble Sort technique.
Algorithm:
START
STEP 1: Input the value of n from the user.
STEP 2: Input n number of string from the user.
STEP 3: Display the unsorted array.
STEP 4: Sort the array using Bubble Sort technique.
STEP 5: Display the sorted array.
STOP
Source Code:
import java.util.*;
public class Bubble_Sort
public static void main(String args[])
Scanner sc= new Scanner(System.in);
int i,j,n,com=0;
String x="";
System.out.println("Enter the number of inputs you want to give : ");
n= sc.nextInt();
String a[]= new String[n];
for(i=0;i<n;i++)
a[i]= sc.next();
System.out.println("The Unsorted Array : ");
for(i=0;i<n;i++)
System.out.print(a[i]+" ,");
for(i=0;i<n;i++)
for(j=0;j<n-i-1;j++)
com=a[j].compareTo(a[j+1]);
if(com>0)
x=a[j];
a[j]=a[j+1];
a[j+1]=x;
System.out.println();
System.out.println("The Sorted Array : ");
for(i=0;i<n;i++)
System.out.print(a[i]+" ,");
}
Output:
Program 10:
Define a class called with the following specifications:
Class name: Eshop
Member variables:
String name: name of the item purchased
double price: Price of the item purchased
Member methods:
void accept(): Accept the name and the price of the item using the
methods of Scanner class.
void calculate(): To calculate the net amount to be paid by a customer,
based on the following criteria:
Price Discount
1000-25000 5.0%
25001-57000 7.5%
57001-100000 10.0%
More than 100000 15.0%
void display(): To display the name of the item and the net amount to
be paid.
Write the main method to create an object and call the above methods.
Algorithm:
START
STEP 1: Define the class Eshop.
STEP 2: Declare the member variables.
STEP 3: Declare a method to accept the name and price of item purchased.
STEP 4: Declare a method to calculate the Net payable amount based on the
given criteria.
STEP 5: Declare a method to display the Item name and The Payable amount.
STEP 6: Call the above methods in the main method.
STOP
Source Code:
import java.util.*;
public class Eshop
{
Scanner sc= new Scanner(System.in);
String name;
double price,amount;
void accept()
System.out.println("Enter Name of Item : ");
name= sc.nextLine();
System.out.println("Enter Price of Item : ");
price= sc.nextDouble();
void calculate()
if(price>=1000 && price<=25000)
amount= price - (5.0/100.0)*price;
else if(price>25000 && price<=57000)
amount= price - (7.5/100.0)*price;
else if(price>57000 && price<=100000)
amount= price - (10.0/100.0)*price;
else if(price>100000)
amount= price - (15.0/100.0)*price;
else
amount= price;
}
void display()
System.out.println("Name of Item purchased : "+name);
System.out.println("Amount to be paid : "+amount);
public static void main(String args[])
Eshop ob= new Eshop();
ob.accept();
ob.calculate();
ob.display();
Output:
INDEX
Sl. No. Title of Program
1 Write a program to input 10 numbers from user and
print the greatest palindrome number.
2 Write a program to input m*n numbers in a double-
dimensional array and display it in matrix format. Then,
sort the rows of the matrix in ascending order.
3 Write a program to check the number of vowels in
each word of a sentence given by the user.
4 Write a program print the following pattern:
9
7 9
5 7 9
3 5 7 9
1 3 5 7 9
5 Write a program to print the following pattern:
9 9 9 9 9
7 7 7 7 7
5 5 5 5 5
3 3 3 3 3
1 1 1 1 1
6 Write a program to print the following pattern:
5
5 4
5 4 3
5 4 3 2
5 4 3 2 1
7 Write a program to print the following series:
1, 11, 111, 1111, 11111, 111111,…………………upto n terms
8 Write a program to input a sentence from user and find
and print the words in the string. Then, display the
reversed form of each word.
9 Write a program to input n number of string in a
single-dimensional array and sort them using Bubble Sort
technique.
10 Define a class called with the following specifications:
Class name: Eshop
Member variables:
String name: name of the item purchased
double price: Price of the item purchased
Member methods:
void accept(): Accept the name and the price of the item
using the methods of Scanner class.
void calculate(): To calculate the net amount to be paid by a
customer, based on the following criteria:
Price Discount
1000-25000 5.0%
25001-57000 7.5%
57001-100000 10.0%
More than 100000 15.0%
void display(): To display the name of the item and the net
amount to be paid.
Write the main method to create an object and call the
above methods.