Professional Documents
Culture Documents
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
circle
3. Display the results.
// checks which
number is divisible by a
System.out.println("Factors are "+i);
}
3. Stop.
// checks
two sider is
which sends i to
power of a and sum is
stored in s
}
3. Sum is displayed.
System.out.println(b);
do
{
c=a+b;
System.out.println(c);
a=b;
b=c;
n=n+1;
}
while(n<=10); }}
8. Stop.
3. Sum is displayed.
// multiplication is done
// sum is found each time of the
product
}
3. Sum is displayed.
// mathematical function is
a to the power of 10
and sum is stored in s
p=(int)s;
convert p to int
System.out.print(p+",");
}
3. Sum is displayed.
import java.io.*;
class seriessq
{
public static void main(String args[])throws IOException
{
InputStreamReader read=new InputStreamReader(System.in);
BufferedReader in=new BufferedReader (read);
int s;s=0;int i;
System.out.println("Enter value of n");
int n=Integer.parseInt(in.readLine());
for(i=1;i<=n;i++)
{
s=s+(1+(i*i));
}
System.out.println("Sum is "+s);
}
}
{
s=s+(1+(i*i));
of i and adds 1 to
it and finds sum and stores
in s
}
for(i=0;i<=n;i++)
// runs till n
{
s=(double)(s+(float)(i*(i+1))/(i+(i+1)));
to following step
and by type casting
converts it to double type
}
3. Stop.
{
if(a%i==0)
{
s=s+i;
}
if(s==a)
{
System.out.println("number is perfect");
}
else
{
System.out.println("number is not perfect");
}
}
}
}
number
{
s=s+i;
3. if(s==a)
// to check the number formed by above
calculations is equal
to original number
int a=Integer.parseInt(in.readLine());
int p;int s;s=0;int d;
p=a*a;
while(p!=0)
{
d=p%10;
s=s+d;
p=p/10;
}
if(s==a)
System.out.println("number is neon");
else
System.out.println("number is not neon");
}
}
number
s=s+d;
the number
p=p/10;
the last digit
}
4. if(s==a)
// to check the number got after above
calculations is equal to
original number
5. If the condition is true then display(number is neon)
else (number is
not neon).
6. Stop.
{
InputStreamReader read=new InputStreamReader(System.in);
BufferedReader in=new BufferedReader(read);
int i; int p; int c=1;
System.out.println("Enter a number");
int a=Integer.parseInt(in.readLine());
p=a*a;
for(i=a;i>0;i/=10)
{
c=c*10;
}
if(p%c==a)
System.out.println("number is automorphic");
else
System.out.println("number is not automorphic");
}
}
number
}
{
public static void main(String args[])throws IOException
{
InputStreamReader read=new InputStreamReader(System.in);
BufferedReader in=new BufferedReader(read);
int a,i,c;c=0;
System.out.println("Enter a number");
a=Integer.parseInt(in.readLine());
for(i=2;i<a;i++)
{
if(a%i==0)
c=1;
}
if(c==0)
System.out.println("number is prime");
else
System.out.println("number is not prime");
}
}
3. if(c==0)
// to check the value of c
4. If the above condition is true then display (number is
prime) else
(number is not prime).
5. Stop.
import java.io.*;
class Armstrong
{
public static void main(String args[])throws IOException
{
InputStreamReader read=new InputStreamReader(System.in);
BufferedReader in=new BufferedReader(read);
int b;int s;s=0;
System.out.println("Enter a number");
int a=Integer.parseInt(in.readLine());
int n;n=a;
while(a>0)
{
b=a%10;
s=s+b*b*b;
a=a/10;
}
if(n==s)
System.out.println("Armstrong Number");
else
System.out.println("Not Armstrong Number");
}
}
greater than 0
{
r=r*10+d;
and d is added
to it so as to convert d to
tens digit
a=a/10;
4. if(k==r)
equal to new
is true than
print it is
palindrome
else
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
assign 1 to t
// checks whether
prime or not
// if above condition is
// if above condition is
}
while(r>0)
{
p=r%10;
if(p!=0)
{
System.out.print(p);
}
r=r/10;
}
}
}
while(a>0)
{
d=a%10;
r=r*10+d;
a=a/10;
digit
}
greater than 0
{
p=r%10;
if(p!=0)
{
System.out.print(p);
the number
}
r=r/10;
4. Stop.
for(i=1;i<=d;i++)
{
f=f*i;
}
s=s+f;
n=n/10;
f=1;
}
if(s==a)
System.out.println("Number is special");
else
System.out.println("Number is not special");
}
}
while(n>0)
than 0
{
d=n%10;
number
// for loop executes
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
number is
special
else
System.out.println("Number is not special"); // if above condition is
false then
print
number is not special
5. Stop.
int a =Integer.parseInt(in.readLine());
for(i=0;i<10;i++)
{
m=a;
while(m>0)
{
d=m%10;
if(d==i)
{
System.out.print(d);
}
m=m/10;
}
}
}
}
2. Loop executesfor(i=0;i<10;i++)
{
m=a;
while(m>0)
0
{
d=m%10;
if(d==i)
{
System.out.print(d);
d
}
m=m/10;
}
}
3. Stop.
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.
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
}
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
}
}
System.out.println("Enter string");
String str=in.readLine();
str=" "+str;
l=str.length();
for(i=1;i<=l;i++)
System.out.println(str.substring(1,i));
}
}
3. Loop executesfor(i=1;i<=l;i++)
System.out.println(str.substring(1,i));
string which is
between 1
and i
4. Stop.
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);
}
}
4. Loop executesfor(i=1;i<p;i++)
{
divisible by any
other number
{
h=i;
value divisible by
both numbers
}
}
return(h); }
9. L.C.M. is takenp=m*n;
c=p/k;
import java.io.*;
class hcf
{
public static void main(String args[])throws IOException
{
InputStreamReader read=new InputStreamReader(System.in);
BufferedReader in=new BufferedReader(read);
System.out.println("Enter a number");
int a=Integer.parseInt(in.readLine());
System.out.println("Enter a number");
int b=Integer.parseInt(in.readLine());
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;
}
}
System.out.println("hcf is"+h);
}
}
3. Loop executesfor(i=1;i<p;i++)
{
if(a%i==0 && b%i==0)
value divisible by
both numbers
}
}
4. H.C.F. is displayed.
// object of the
class is created
4. k=ob.reverse(a);
5. if(k==c)