Beruflich Dokumente
Kultur Dokumente
Charge
Up to 100 units
paise/unit
80
1 Re/unit
1,25 Rs/unit
{
c=((100*80)+(100*100)+(u-200)*125)/100;
a=c+50;
}
System.out.println("unit consumed"+u);
System.out.println("charge=Rs"+c);
System.out.println("additional charges=Rs50");
System.out.println("amount to be paid=Rs"+a);
}
public static void main(String args[])throws IOException
{
int un;un=0;
InputStreamReader read=new InputStreamReader(System.in);
BufferedReader in=new BufferedReader(read);
electricity obj=new electricity();
System.out.println("Enter the unit consumed");
un=Integer.parseInt(in.readLine());
obj.charge(un);
}}}
calculations
{
c=(u*80)/100;
charged
a=c+50;
7. Function is called.
obj.charge(un);
discount
5%
2001 to5000
25%
5001 to 10000
35%
Above 10000
50%
import java.io.*;
class discount
{
public static void main(String args[])throws IOException
{
InputStreamReader read=new InputStreamReader(System.in);
BufferedReader in=new BufferedReader(read);
int c;
double pay=0,d=0;
System.out.println("Enter total cost");
c=Integer.parseInt(in.readLine());
if(c<=2000)
d=(double)5/100*c;
if((c>2000)&&(c<=5000))
d=(double)25/100*c;
if((c>5000)&&(c<=10000))
d=(double)35/100*c;
if(c>10000)
d=(double)50/100*c;
pay=c-d;
System.out.println("discount"+d);
System.out.println("amount to be paid"+pay);
}
}
Algorithm1. Accept total cost from the user and store it in variable
c.
2. if(c<=2000)
2000 then written
calculations are
made
d=(double)5/100*c;
First
Second
Pass
if(m>=80)
System.out.println("Distinction");
if((m>=60)&&(m<80))
System.out.println("First Division");
if((m>=45)&&(m<60))
System.out.println("Second Division");
if((m>=40)&&(m<45))
System.out.println("Promotion not granted");
}
}
8%
9%
{
public static void main(String args[])throws IOException
{
InputStreamReader read=new InputStreamReader(System.in);
BufferedReader in=new BufferedReader(read);
int p,m,ch;
float n;
System.out.println("Enter the principal");
p=Integer.parseInt(in.readLine());
System.out.println("Enter 1 for 6 months,2 for more than 6-12 months");
System.out.println("Enter 3 for 12-36 months,4 for more than 36 months");
System.out.println("Enter choice");
ch=Integer.parseInt(in.readLine());
m=Integer.parseInt(in.readLine());
n=(float)m/12;
switch(ch)
{
case 1:
System.out.println("Sum is"+p*(Math.pow(1.07,n)));
break;
case 2:
System.out.println("Sum is"+p*(Math.pow(1.08,n)));
break;
case 3:
System.out.println("Sum is"+p*(Math.pow(1.09,n)));
break;
case 4:
System.out.println("Sum is"+p*(Math.pow(1.1,n)));
break;
default:
System.out.println("Wrong choice");
}}
{
d=a%10;
s=s+d;
a=a/10;
}
System.out.println("sum of the number is"+s);
}
}
than 0
{
d=a%10;
s=s+d;
0
a=a/10;
digit
}
int b =Integer.parseInt(in.readLine());
System.out.println("Enter c");
int c =Integer.parseInt(in.readLine());
d=Math.sqrt(b*b-4*a*c);
if(d>0)
System.out.println("Unequal");
if(d==0)
System.out.println("Equal");
if(d<0)
System.out.println("Imaginary");
}
}
// discriminant is found
System.out.println("Unequal");
if(d==0)
System.out.println("Equal");
if(d<0)
System.out.println("Imaginary");
4. Stop.
Rs 20 / kg
For next 20 kg
Rs 10/kg
For next 20 kg
Rs 8/kg
More than 50 kg
Rs 5/kg
import java.io.*;
class parcel
{
public static void main(String args[])throws IOException
{
InputStreamReader read=new InputStreamReader(System.in);
3. Stop
{
InputStreamReader read=new InputStreamReader(System.in);
BufferedReader in=new BufferedReader (read);
int i; int j;int p; int t;p=0;t=0;
System.out.println("Enter first number");
int a =Integer.parseInt(in.readLine());
System.out.println("Enter second number");
int b =Integer.parseInt(in.readLine());
for(i=2;i<a;i++)
{
if(a%i==0)
p=1;
}
for(j=2;j<b;j++)
{
if(b%j==0)
t=1;
}
if(p==0 && t==0 && Math.abs(a-b)==2)
System.out.println("Twin Prime");
else
System.out.println("Not Twin Prime");
}
}
itself
p=1;
to p
}
t=1;
assign 1 to t
// checks whether
prime or not
// if above condition is
// if above condition is
r=r/10;
}
}
}
digit
}
greater than 0
{
p=r%10;
if(p!=0)
{
System.out.print(p);
the number
}
r=r/10;
4. Stop.
if(s==a)
System.out.println("Number is special");
else
System.out.println("Number is not special");
}
}
than 0
{
d=n%10;
number
for(i=1;i<=d;i++)
{
f=f*i;
number stored
in d or finds the factorial of the
number stored in d
}
s=s+f;
// assign 1 to f
4. if(s==a)
stored in s is
number or not
System.out.println("Number is special");
// if above condition is
false then
print
number is not special
5. Stop.
if(d==i)
{
System.out.print(d);
}
m=m/10;
}
}
}
}
d=m%10;
if(d==i)
{
System.out.print(d);
d
}
m=m/10;
}
}
3. Stop.
for(i=0;i<10;i++)
{
System.out.println("Enter number");
m[i]=Integer.parseInt(in.readLine());
}
for(i=0;i<9;i++)
{
min =i;
for(j=i+1;j<10;j++)
{
if(m[min]>m[j])
min=j;
}
t=m[i];
m[i]=m[min];
m[min]=t;
}
System.out.println("numbers are in ascending order");
for(i=0;i<10;i++)
System.out.println(m[i]); }}
min=j;
than it
interchange their position
m[min]=t;
{
for(j=0;j<(9-i);j++)
the array
{
if(m[j]>m[j+1])
greater or not
3. If the above condition is true then interchanges the
position of first
element with second otherwise pass on to next
element
{
t=m[j];
m[j]=m[j+1];
m[j+1]=t;
}}}
else
System.out.println("number is not searched");
}
}
if(a==m[j])
is equal to
number to be searched
f=1;
4.
if(f==1)
the user
{k=1;a=i;}
then assign k to 1
and a to I
}
4. if(k==1)
// display if above
condition is true
else
System.out.println("Not found");
found
5. Stop.
}
}
for(i=0;i<4;i++)
{
for(j=0;j<4;j++)
{
if(m[i][j]!=m[j][i])
k=k+1;
}
}
if(k==0)
System.out.println("Symmetric");
else
System.out.println("Not Symmetric");
}
}
{
if(m[i][j]!=m[j][i])
// checks whether element of i th row and j th
column is not equal to j th row and i th column
k=k+1;
}
}
3. if(k==0)
{
sum=sum+m[j][2-j];
}
System.out.println("Sum of right diagonal "+sum);
}
}
s=s+m[i][i];
diagonal
}
System.out.println("Sum of left diagonal "+s);
}
System.out.println("Sum of right diagonal "+sum);
4. Stop.
import java.io.*;
class swap
{
public static void main(String args[])throws IOException
{
InputStreamReader read=new InputStreamReader(System.in);
BufferedReader in=new BufferedReader(read);
int i;int k;int t;int j;
int m[][]=new int[4][4];
System.out.println("Enter the numbers");
for(i=0;i<4;i++)
{
for(j=0;j<4;j++)
{
m[i][j]=Integer.parseInt(in.readLine());
}
}
System.out.println("Input is-");
for(i=0;i<4;i++)
{
for(j=0;j<4;j++)
{
System.out.print(m[i][j]+" ");
}
System.out.println();
}
for(k=0;k<4;k++)
{
t=m[0][k];
m[0][k]=m[3][k];
m[3][k]=t;
}
System.out.println("Matrix is-");
for(i=0;i<4;i++)
{
for(j=0;j<4;j++)
{
System.out.print(m[i][j]+" ");
}
System.out.println();
}
}
}
for(k=0;k<4;k++)
{
t=m[0][k];
m[0][k]=m[3][k];
m[3][k]=t;
r[k]=m[k];
}
for(i=0;i<4;i++)
{
r[t]=n[i];
t=t+1;
}
System.out.println("Merged array");
for(i=0;i<10;i++)
{
System.out.println(+r[i]);
}
}
}
t=t+1;
}
}
System.out.println("Frequency of "+n+" is "+t);
}
}
r=(r*10)+p;
t=t/10;
}
if(m[j]==r)
System.out.print(r+" ");
r=0;
}
}
}
m[i]=m[min];
m[min]=t;
}
for(i=0;i<6;i++)
{
System.out.println(m[i]);
}
}
}
if(m[j]==10)
System.out.print("A");
if(m[j]==11)
System.out.print("B");
if(m[j]==12)
System.out.print("C");
if(m[j]==13)
System.out.print("D");
if(m[j]==14)
System.out.print("E");
if(m[j]==15)
System.out.print("F");
}
else
System.out.print(m[j]);
}
}
}
Algorithm-
{
int i; int p;int h=0;p=a*b;
for(i=1;i<p;i++)
{
if(a%i==0 && b%i==0)
{
h=i;
}
}
return(h);
}
public static void main(String args[])throws IOException
{
InputStreamReader read=new InputStreamReader(System.in);
BufferedReader in=new BufferedReader(read);
int m, n,p,k,c;k=0;c=0;
cal obj=new cal();
System.out.println("Enter two numbers");
m=Integer.parseInt(in.readLine());
n=Integer.parseInt(in.readLine());
k=obj.hcf(m,n);
p=m*n;
c=p/k;
System.out.println("H.C.F.is"+k);
System.out.println("L.C.M.is"+c);
}
}
divisible by any
other number
{
h=i;
value divisible by
both numbers
}
}
return(h); }
8. k=obj.hcf(m,n);
given by it is
9. L.C.M. is takenp=m*n;
c=p/k;
while(n!=0);
return(r);
}
public static void main(String args[])throws IOException
{
InputStreamReader read=new InputStreamReader(System.in);
BufferedReader in=new BufferedReader (read);
int k,r,d,c;r=0;
System.out.println("Enter a number");
int a =Integer.parseInt(in.readLine());
c=a;
functionpallindrome ob= new functionpallindrome();
k=ob.reverse(a);
if(k==c)
System.out.println("Pallindrome");
else
System.out.println("Not pallindrome");
}
}
// object of the
class is created
4. k=ob.reverse(a);
5. if(k==c)
{
public static void main(String args[])throws IOException
{
InputStreamReader read=new InputStreamReader(System.in);
BufferedReader in=new BufferedReader(read);
int x,y,v;v=0;
String a;
char b;
System.out.println("Enter a string");
a=in.readLine();
x=a.length();
for(y=0;y<x;y++)
{
b=(a.charAt(y));
if((b=='a')||(b=='i')||(b=='o')||(b=='o')||(b=='u')||(b=='A')||(b=='I')||
(b=='O')||(b=='U')||(b=='E'))
v=v+1;
}
System.out.println("number of vowels are"+v);
}
}
2. x=a.length();
3. Loop executesfor(y=0;y<x;y++)
{
b=(a.charAt(y));
string
if((b=='a')||(b=='i')||(b=='o')||(b=='o')||(b=='u')||
// to check
character is
Vowel or not
(b=='A')||(b=='I')||(b=='O')||(b=='U')||(b=='E'))
v=v+1;
found
}
{
InputStreamReader read=new InputStreamReader(System.in);
BufferedReader in=new BufferedReader(read);
String name;
int up,low,digit,spl,l,i;up=0;low=0;spl=0;digit=0;
char chr;
System.out.println("Enter a string");
name=in.readLine();
l=name.length();
for(i=l-1;i>=0;i--)
{
chr=name.charAt(i);
if(chr>='A'&&chr<='Z')
up=up+1;
else if(chr>='a'&&chr<='z')
low=low+1;
else if(chr>='0'&&chr<='9')
digit=digit+1;
else
spl=spl+1;
}
System.out.println("No. of uppercase"+up);
System.out.println("No. of lowercase"+low);
System.out.println("No. of digits"+digit);
System.out.println("No. of special character"+spl);
}
}
3. Loop executesfor(i=l-1;i>=0;i--)
{
chr=name.charAt(i);
string one by
one
if(chr>='A'&&chr<='Z')
or not
up=up+1;
// increment in variable up if
character is in
upper case
else if(chr>='a'&&chr<='z')
not
low=low+1;
character is in
lower case
else if(chr>='0'&&chr<='9')
// to check it is in number or
not
digit=digit+1;
character any
digit
else
spl=spl+1;
character any
special symbol
}
{
if(m[i].equals(ch));
{k=1;a=i;}
}
if(k==1)
System.out.println("The capital is"+n[a]);
else
System.out.println("The stae entered does not exists in array");
}
}
Algorithm1. Accept all states and all capitals in two arrays such that
they each
should have same index number as its capital.
2. Accept the state whose capital user wants to search.
3. Loop executesfor(i=0;i<5;i++)
{
if(m[i].equals(ch));
is present or not
{k=1;a=i;}
assign 1 to k and
store the index number of
the city
}
4. if(k==1)
found or not
// if the above
display this
5. Stop.
// else
3. Loop executesfor(i=0;i<a;i++)
{
chr=name.charAt(i);
or not
b=b+1;
then increment in
variable b
}
4. w=b+1;
they will be one
of spaces
5. System.out.println("No. of blank spaces" + b);
// to print no. of
spaces
System.out.println("No. of words" + w);
// to print no. of
words
System.out.println("No. of alphabets" + (a-b));
// to print no. of
alphabets as
they will be equal to the
difference between total no. of
characters and no. of spaces
}
}
6. Stop.
3. Loop executesfor(z=0;z<x;z++)
{
p=str.charAt(z);
f=f+1;
increment in f
t="";
}
}
// to check
{
System.out.println(chr+" is a letter");
// if above condition
is true then
display that
it is a letter
if(Character.isUpperCase(chr))
// to check it is in
// if above
// to check it is in
is true then
print that
it is in lower case
}
else
{
if(Character.isDigit(chr))
// to check it is digit or
not
System.out.println(chr+" is a digit");
// if above condition is
// if all above
3. Stop.
2. l=word.length();
string or word
for(i=l-1;i>=0;i--)
{
chr=word.charAt(i);
of the word
word1=word1+chr;
last to the
string word1
}
4. if(word.equals(word1))
by reversing the
then print it is
palindrome
else
System.out.println("Not Pallindrome");
// if above condition is
}
}
3. Loop executesfor(i=0;i<l;i++)
{
ch=str.charAt(i);
// to check the
character is vowel
or not
||ch=='a'||ch=='e'||ch=='i'||ch=='o'||ch=='u')
break;
4. st=str.substring(i,l);
after the first
string
s=str.substring(0,i);
starting to the
first vowel
System.out.println(st+s+"ay");
display them
5. Stop
3. Loop executesfor(i=0;i<l;i++)
{
ch=str.charAt(i);
one
if(ch=='A')
f=f+1;
in f by one
if(ch=='a')
k=k+1;
in k by one
}
}
}
Algorithm1. Accept two string from the user having same length.
2. Find length of any of the string.
3. Loop executesfor(i=0;i<l;i++)
{
s=s+str.charAt(i)+st.charAt(i);
4. Stop.
3. Loop executesfor(i=0;i<l;i++)
{
ch=str.charAt(i);
one
if((ch==',')||(ch=='.')||(ch==';')||(ch=='?')||(ch=='!'))
above character is equal to any puncuation
// to check whether
{
k=k+1;
the value of k
}
}
}
3. Loop executesfor(j=65;j<=90;j++)
code of A to Z
{
for(i=0;i<l;i++)
the string
if(ch==(char)j||ch==(char)(j+32))
particular
// checks whether a
character of
the string is equal to
character
having ASCII code of j
System.out.print(ch);
// if above condition is
4. Stop.
4. Loop executesfor(y=0;y<x;y++)
{
b=str.charAt(y);
if(b==' ')
{
d=d+1;
if(d==1)
st=st+"."+(str.charAt(y+1));
the space
if(d==2)
st=st+"."+(str.substring(y,x));
second space
}
}
Stringm[]={"","one","two","three","four","five","six","seven","eight","nine","t
en","eleven","twelve"thirteen","fourteen","fifteen","sixteen","seventeen","ei
ghteen","nineteen","twenty",
"thirty","forty","fifty","sixty","seventy","eighty","ninety","hundred","thousand
"};
if(a>0&&a<=20)
{
System.out.println(m[a]);
}
if(a>20&&a<=100)
{
p=a%10;
d=a/10;
System.out.println(m[20+(d-2)]+" "+m[p]);
}
if(a>100&&a<1000)
{
n=a%100;
b=n%10;
v=n/10;
c=a/100;
System.out.println(m[c]+" hundred "+m[20+(v-2)]+" "+m[b]);
}
}
}