Comp Prject11
Comp Prject11
WAP to input a string and count the number of vowels present in the
string.
class vowels{
public static void main(String S){
S=S.trim();
int l=S.length();
S=S.toUpperCase();
int c=0;
for(int i=0; i<l; i++)
{
char ch=S.charAt(i);
if(ch=='A' || ch=='E' || ch=='O' || ch=='I' || ch=='U' )
{
c++;
}
}
System.out.println("Number of vowels =" + c);
}
}
OUTPUT
(String S= “classmate”)
int c=0;
for(int i=0; i<l; i++)
{
char ch=S.charAt(i);
if(ch==' ' )
{
c++;
}
}
System.out.println("Number of words =" +( c+1));
}
}
OUTPUT
import java.util.Scanner;
class c{
public static void main(){
Scanner sc=new Scanner (System.in);
System.out.println("Enter a sentence");
String S=sc.nextLine();
S=S.trim();
S=S + " ";
int l=S.length();
String NS="";
for (int i=0; i<l ; i++)
{
char ch=S.charAt(i);
if (ch!=' ')
{
NS=NS+ch;
}
else
{
System.out.println(NS);
System.out.println( NS.length());
NS="";
}
}
}}
OUTPUT
class vowels{
public static void main(String S){
S=S.trim();
S=S.toUpperCase();
int l=S.length();
String NS=" ";
for(char ch='A' ; ch<='Z'; ch++)
{
for(int i=0; i<l; i++)
{
if(S.charAt(i)==ch)
{
NS=NS+ ch;
}}}
System.out.println(NS);
}
}
OUTPUT
(String S=”Priya”)
{
NS=NS+ ch;}}}
return NS;
}
public static void main(String S1, String S2){
anagram ob=new anagram();
String P=ob.Arrange(S1);
String Q=ob.Arrange(S2);
if(P.compareTo(Q)==0)
System.out.println(P+" " +Q +" "+ "are anagram strings");
else
System.out.println("NO");}}
OUTPUT
import java.util.Scanner;
class employee
{
int eno,age;
String ename;
double basic,net;
void accept()
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter details");
eno=sc.nextInt();
age=sc.nextInt();
ename=sc.next();
basic=sc.nextDouble();
}
void calculate()
{
double hra=(18*basic)/100.0;
double da=(17.45*basic)/100.0;
double pf=(18.10*basic)/100.0;;
net=basic+hra+da-pf;
if(age>50)
{
net+=5000;
}
}
void print()
{
System.out.println("eno"+ eno +"\t ename"+ ename);
System.out.println("age="+age +"\t basic " +basic);
System.out.println("Net" + net);
}
public static void main()
{
employee ob= new employee();
ob.accept();
ob.calculate();
ob.print();
}
}
OUTPUT
class pp{
void pattern()
{
for(int i=4; i>=1; i--)
{
for(int j=i;j>=1; j--)
{
System.out.print(j + " ");
}
System.out.println();
}
}
void pattern(int r,int c)
{
for(int i=1; i<=r; i++)
{
for(int j=1; j<=c; j++){
System.out.print(j+ " ");}
System.out.println();
}
}
OUTPUT
VARIABLE DESCRIPTION TABLE
VARIABLE DATA TYPE PURPOSE
r int to store the number of
rows
j int Counter variable
i int Counter variable
c int To store the number of
columns
OUTPUT
VARIABLE DESCRIPTION TABLE
VARIABLE DATA TYPE PURPOSE
R double To store the radius
H double to store the height
L double To store the length
B double To store the breadth
V double To store the volume
19. A DTDC courier company chargesfor the courier based on the weight of
the parcel . Define a class with the following specifications
1)class name courier
2)member variable
name
weight
address
bill
Type ‘D’ for domestic and ‘I’ for international
3)member methods
void accept ()
void calculate()
WEIGHT PRICE /Kg
First 5 kg 800/-
Next 5 kg 700/-
Above 10kg 500/-
import java.util.Scanner;
class employee
{
int bill,weight;
String name,address;
char type ;
void accept()
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter details");
name=sc.next();
weight=sc.nextInt();
address=sc.next();
bill=sc.nextInt();
System.out.println("Enter \' D\' for domestic and \' I\' for international");
type=sc.next().charAt(0);
}
void calculate()
{
if(weight<=5)
{
bill=weight*800;
}else
{
bill=(5*800)+ (5*700)+(weight -10) *500;
if (type== 'I')
{bill=bill+1500;
}
}
void print()
{
System.out.println("bill=" + bill);
System.out.println("name=" + name);
System.out.println("address=" + address);
System.out.println("type=" + type);
}
public static void main(){
employee ob=new employee();
ob.accept();
ob.calculate();
ob .print();
}
}
OUTPUT
20. WAP to create a method double S1(int ,int,int) . Invoke the above method
from the main function.
class pp{
double SI(int R, int T, int P)
{double s=(P*T*R) /100.0;
return s;
}
void main(int p, int r, int t)
{
pp ob=new pp();
double Q=ob.SI(p,t,r);
System.out.println(R);
}
OUTPUT
(p=500, r=5, t=5)
PROJECT
NAME : Siddhima Goel
CLASS : X SECTION: F
SUBJECT: Computer
ROLL NUMBER: 45