Ex 5.2:-To Implement A Program To Accept A String From The Console and Count Number of Vowels, Consonant, Digits, Tabs and Blank Spaces in A String
Ex 5.2:-To Implement A Program To Accept A String From The Console and Count Number of Vowels, Consonant, Digits, Tabs and Blank Spaces in A String
2:- To implement a program to accept a string from the console and count number of
vowels, consonant, digits, tabs and blank spaces in a string.
import java.io.*;
import java.util.*;
class filter
{
String x,y;
int count1=0,count2=0,count3=0,count4=0,count5=0;
filter(String z)
{
x=z;
}
void counter()
{
int l=x.length();
for(int i=0;i<l;i++)
{
char b=x.charAt(i);
if(b=='a'||b=='e'||b=='i'||b=='o'||b=='u')
count1++;
else if(b=='0'||b=='1'||b=='2'||b=='3'||b=='4'||b=='5'||b=='6'||b=='7'||b=='8'||b=='9')
count2++;
else if(b=='\t')
count3++;
else if(b=='\b')
count4++;
else
count5++;
}
System.out.println("lenght : "+l);
System.out.println("Vowels : "+count1+" consonant : "+count5+" digits : "+count2+" tabs :
"+count3+" blank : "+count4);
}
}
class ex52
{
public static void main(String args[])throws IOException
{
System.out.println("\n Name:- Chaan \n");
BufferedReader in=new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter String :- ");
String s=in.readLine();
filter f=new filter(s);
f.counter();}}
Ex 5.2:- To implement a program to accept a string from the console and count number of
vowels, consonant, digits, tabs and blank spaces in a string.
import java.io.*;
import java.util.*;
class filter
{
String x,y;
int count1=0,count2=0,count3=0,count4=0,count5=0;
filter(String z)
{
x=z;
}
void counter()
{
int l=x.length();
for(int i=0;i<l;i++)
{
char b=x.charAt(i);
if(b=='a'||b=='e'||b=='i'||b=='o'||b=='u')
count1++;
else if(b=='0'||b=='1'||b=='2'||b=='3'||b=='4'||b=='5'||b=='6'||b=='7'||b=='8'||b=='9')
count2++;
else if(b=='\t')
count3++;
else if(b=='\b')
count4++;
else
count5++;
}
System.out.println("lenght : "+l);
System.out.println("Vowels : "+count1+" consonant : "+count5+" digits : "+count2+" tabs :
"+count3+" blank : "+count4);
}
}
class ex52
{
public static void main(String args[])throws IOException
{
System.out.println("\n Name:- Roshni \n ");
BufferedReader in=new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter String :- ");
String s=in.readLine();
filter f=new filter(s);
f.counter();}}
Ex 6.2:- Implement a program to accomplish the following task using String/StringBuffer
class.
1-Accept password from user
2-Check if password is correct then display “GOOD”
Else display “Incorrect Password”
3-Append the password with the string “welcome to java”
4-Display the password in reverse order.
5-Replace the character ‘i’ in password with “*” character.
import java.io.*;
import java.lang.*;
class test
{
String s1=new String();
String s2;
test(String s)
{
s1=s;
}
void task1()
{
if(s1.equals("ab!cd"))
{
s2=s1.concat(" Welcome To java ");
System.out.println("GOOD");
System.out.println(s2);
}
else
System.out.println("Incorrect Password");
s2=s1.replaceAll("!","*");
System.out.println("Replacing :- "+s2);
}}
class ex62
{
public static void main(String args[])throws IOException
{
System.out.println("\n Name:- Chaan \n");
BufferedReader in=new BufferedReader(new InputStreamReader(System.in));
String x;
System.out.println("Enter a password : ");
x=in.readLine();
test t=new test(x);
t.task1();
}
}
Ex 6.2:- Implement a program to accomplish the following task using String/StringBuffer
class.
1-Accept password from user
2-Check if password is correct then display “GOOD”
Else display “Incorrect Password”
3-Append the password with the string “welcome to java”
4-Display the password in reverse order.
5-Replace the character ‘i’ in password with “*” character.
import java.io.*;
import java.lang.*;
class test
{
String s1=new String();
String s2;
test(String s)
{
s1=s;
}
void task1()
{
if(s1.equals("ab!cd"))
{
s2=s1.concat(" Welcome To java ");
System.out.println("GOOD");
System.out.println(s2);
}
else
System.out.println("Incorrect Password");
s2=s1.replaceAll("!","*");
System.out.println("Replacing :- "+s2);
class ex62
{
public static void main(String args[])throws IOException
{
System.out.println("\n Name:- Roshni \n");
BufferedReader in=new BufferedReader(new InputStreamReader(System.in));
String x;
System.out.println("Enter a password : ");
x=in.readLine();
test t=new test(x);
t.task1();
}
}
Ex 7.3:- Write a program to accept 10 number in an array and display the number in
ascending order (use Bubble sort)
import java.io.*;
class sorting
{
int a[]=new int[10];
BufferedReader in=new BufferedReader(new InputStreamReader(System.in));
void getdata() throws IOException
{
System.out.print("Enter any 10 numbers : ");
for(int i=0;i<10;i++)
{
a[i]=Integer.parseInt(in.readLine());
}
}
void putdata()
{
for(int i=0;i<10;i++)
{
for(int j=i+1;j<10;j++)
{
if(a[i]>a[j])
{int temp;
temp=a[j];
a[j]=a[i];
a[i]=temp;}
}
}
System.out.print("Sorted output :- ");
for(int i=0;i<10;i++)
{System.out.print(" "+a[i]); }
}
}
class ex73
{
public static void main(String args[]) throws IOException
{
System.out.print("\n Name : Chaan \n\n ");
sorting s=new sorting();
s.getdata();
s.putdata();
}
Ex 7.3:- Write a program to accept 10 number in an array and display the number in
ascending order (use Bubble sort)
import java.io.*;
class sorting
{
int a[]=new int[10];
BufferedReader in=new BufferedReader(new InputStreamReader(System.in));
void getdata() throws IOException
{
System.out.print("Enter any 10 numbers : ");
for(int i=0;i<10;i++)
{
a[i]=Integer.parseInt(in.readLine());
}
}
void putdata()
{
for(int i=0;i<10;i++)
{
for(int j=i+1;j<10;j++)
{if(a[i]>a[j])
{int temp;
temp=a[j];
a[j]=a[i];
a[i]=temp; } }
}
System.out.print("Sorted output :- ");
for(int i=0;i<10;i++)
{System.out.print(" "+a[i]); }
}
}
class ex73
{
public static void main(String args[]) throws IOException
{
System.out.print("\n Name : Roshni \n\n ");
sorting s=new sorting();
s.getdata();
s.putdata();
}}
Ex 8.2:- Program to implement a vector that creates and stores five integer objects, three
String objects, two character objects, two float objects such that to accomplish the
following
1. to add object at the end of vector
2. to remove 2nd object from the vector
3. to search for a particular object in vector
4. to display first and last elements in vector
5. to display the list of objects in vector
import java.util.*;
class ex82
{
public static void main(String args[])
{
System.out.println("\n Name :- Chaan \n");
Vector v=new Vector();
v.addElement(new Integer(1));
v.addElement(new Integer(2));
v.addElement(new Integer(3));
v.addElement(new Integer(4));
v.addElement(new Integer(5));
v.addElement("abc");
v.addElement("def");
v.addElement("ghi");
v.addElement('x');
v.addElement('y');
v.addElement(new Float(1.1));
v.addElement(new Float(2.2));
System.out.println("\n As per Question all 12 elements are added ");
System.out.println("\n Initial Size : "+v.size());
v.insertElementAt(new Integer(6),12);
System.out.println("\n 1.After adding object at the end of vector : "+v.size());
v.removeElementAt(1);
System.out.println("\n 2.After removing 2nd object from vector : "+v.size());
System.out.println("\n 3.Searching vector at 5th position : "+v.elementAt(4));
System.out.println("\n 4.first element in vector : "+v.firstElement()+" last element in vector :
"+v.lastElement());
System.out.println("\n 5.list of objects in vector : "+v.subList(0,12));
}
}
Ex 8.2:- Program to implement a vector that creates and stores five integer objects, three
String objects, two character objects, two float objects such that to accomplish the
following
1. to add object at the end of vector
2. to remove 2nd object from the vector
3. to search for a particular object in vector
4. to display first and last elements in vector
5. to display the list of objects in vector
import java.util.*;
class ex82
{
public static void main(String args[])
{
System.out.println("\n Name :- Roshni \n");
Vector v=new Vector();
v.addElement(new Integer(1));
v.addElement(new Integer(2));
v.addElement(new Integer(3));
v.addElement(new Integer(4));
v.addElement(new Integer(5));
v.addElement("abc");
v.addElement("def");
v.addElement("ghi");
v.addElement('x');
v.addElement('y');
v.addElement(new Float(1.1));
v.addElement(new Float(2.2));
System.out.println("\n As per Question all 12 elements are added ");
System.out.println("\n Initial Size : "+v.size());
v.insertElementAt(new Integer(6),12);
System.out.println("\n 1.After adding object at the end of vector : "+v.size());
v.removeElementAt(1);
System.out.println("\n 2.After removing 2nd object from vector : "+v.size());
System.out.println("\n 3.Searching vector at 5th position : "+v.elementAt(4));
System.out.println("\n 4.first element in vector : "+v.firstElement()+" last element in vector :
"+v.lastElement());
System.out.println("\n 5.list of objects in vector : "+v.subList(0,12));
}
}
Ex 9.2:- Program to implement the following Multi Level inheritance:
Class:Account{cust_name,acc_no}Class:Saving_Acc{min_bal,saving_bal}
Class:Acct_Details{deposits,withdrawals}
import java.lang.*;
import java.io.*;
class Account
{
String cust_name;
int acc_no;
Account(String cn,int an)
{
cust_name=cn;
acc_no=an;
}
void disp1()
{
System.out.println("=======Account Details============");
System.out.println("Customer Name :- "+cust_name);
System.out.println("Account number :- "+acc_no);
}
}
class ex92
{
public static void main(String args[]) throws IOException
{
System.out.println("\n Name :- Chaan \n");
Acct_Details a=new Acct_Details("abc",123,1000);
a.disp3();
a.trans();
}
}
Ex 9.2:- Program to implement the following Multi Level inheritance:
Class:Account{cust_name,acc_no}Class:Saving_Acc{min_bal,saving_bal}
Class:Acct_Details{deposits,withdrawals}
import java.lang.*;
import java.io.*;
class Account
{
String cust_name;
int acc_no;
Account(String cn,int an)
{
cust_name=cn;
acc_no=an;
}
void disp1()
{
System.out.println("=======Account Details============");
System.out.println("Customer Name :- "+cust_name);
System.out.println("Account number :- "+acc_no);
}
}
class ex92
{
public static void main(String args[]) throws IOException
{
System.out.println("\n Name :- Roshni \n");
Acct_Details a=new Acct_Details("abc",123,1000);
a.disp3();
a.trans();
}
}
Ex 10.1:- Program to implement the following Multiple Inheritance:
Interface: Exam{Percen_cal()} Class:Student{name,roll_no,mark1,mark2}
import java.lang.*;
interface Exam
{
void percent_cal();
}
class Student
{
String name;
int roll_no,mark1,mark2;
void getdata(String n,int r,int m1,int m2)
{
name=n;
roll_no=r;
mark1=m1;
mark2=m2;
}
void putdata()
{
System.out.println("Name: "+name);
System.out.println("Roll No: "+roll_no);
System.out.println("Marks Sub1: "+mark1+"\t Sub2: "+mark2);
}
}
import java.lang.*;
interface Exam
{
void percent_cal();
}
class Student
{
String name;
int roll_no,mark1,mark2;
void getdata(String n,int r,int m1,int m2)
{
name=n;
roll_no=r;
mark1=m1;
mark2=m2;
}
void putdata()
{
System.out.println("Name: "+name);
System.out.println("Roll No: "+roll_no);
System.out.println("Marks Sub1: "+mark1+"\t Sub2: "+mark2);
}
}
void area()
{
float a=dim1*dim2;
System.out.println("Area of Rectangle :- "+a);
}
}
class Triangle extends Shape
{
Triangle(float d1,float d2)
{
super(d1,d2);
}
void area()
{
float a=(dim1*dim2)/2;
System.out.println("Area of Triangle :- "+a);
}
}
class ex111
{
public static void main(String args[])
{
System.out.println("\n Name : Chaan \n");
Rectangle r=new Rectangle(5,5);
Triangle t=new Triangle(10,10);
r.area();
t.area();
}
}
Ex 11.1:- Program to implement Method Overriding for following inheritance: (Assume
data)
Abstract Class: Shape {dim1,dim2,abstract area()}
void area()
{
float a=dim1*dim2;
System.out.println("Area of Rectangle :- "+a);
}
}
class Triangle extends Shape
{
Triangle(float d1,float d2)
{
super(d1,d2);
}
void area()
{
float a=(dim1*dim2)/2;
System.out.println("Area of Triangle :- "+a);
}
}
class ex111
{
public static void main(String args[])
{
System.out.println("\n Name : Roshni \n");
Rectangle r=new Rectangle(10,10);
Triangle t=new Triangle(20,20);
r.area();
t.area();
}
}