Вы находитесь на странице: 1из 32

Acknowledgement

It is my proud privilege to place on record


my deep and sincerest gratitude to almighty ,
my parents and my teacher , who have been
source of constant support through my project
work.
Name:
Arjun Sogarwal
Certificate

This is to certify that is project of Computer


is prepared by Arjun Sogarwal of class X-B under
my guidance.

Arjun Sogarwal. Mr.Sanjay Chauhan


Q-1. Write a program to check whether the number is
Positive Or Negative.
import java.io.*;
class check
{
public static void main(String args[])
throws IOException
{
BufferedReader br=new BufferedReader(new InputStreamReader-
(System.in));
System.out.println("Enter a number");
int a=Integer.parseInt(br.readLine());
if (a>0)
{
System.out.println("The number is positive"+a);
}
else if(a<0)
{
System.out.println("The number is negative"+a);
}
}
}

Q-2.Write a program to check whether the number is


Even or Odd.
import java.io.*;
class even
{
public static void main(String args[])
throws IOException
{
BufferedReader br=new BufferedReader(new InputStreamRead-er
(System.in));
System.out.println("Enter a number");
int a=Integer.parseInt(br.readLine());
if(a%2==0)
{
System.out.println("The number is even"+a);
}
else
{
System.out.println("The number is odd"+a);
}
}
}

Q-3.Write a program to input a number and print the


sum of it’s digits.
import java.io.*;
class sum
{
public static void main(String args[])
throws IOException
{
BufferedReader br=new BufferedReader(new InputStreamReader-
(System.in));
System.out.println("Enter a number");
int n=Integer.parseInt(br.readLine());
int d=0,sum=0;
while(n>0)
{
d=n%10;
sum=sum+d;
n=n/10;
}
System.out.println("sum="+sum);
}
}

Q-4.Write a program to check whether the number is


Palindrome or Not.
import java.io.*;
class o
{
public static void main(String args[])
throws IOException
{
BufferedReader br=new BufferedReader(new InputStreamReader-
(System.in));
System.out.println("Enter a number");
int a=Integer.parseInt(br.readLine());
int q=0,r,t;
t=a;
while(a>0)
{
r=a%10;
q=(q*10)+r;
a=a/10;
}
if(t==q)
{
System.out.println("The number is palindrome");
}
else
{
System.out.println("The number is not palindrome");
}
}
}

Q-5.Write a program to check whether the number is


Armstrong or Not.
import java.io.*;
class armstrong
{
public static void main(String args[])
throws IOException
{
BufferedReader br=new BufferedReader(new InputStreamReader-
(System.in));
System.out.println("Enter a number");
int a=Integer.parseInt(br.readLine());
int s=0,r,t;
t=a;
while(a>0)
{
r=a%10;
s=s+(r*r*r);
a=a/10;
}
if(t==s)
{
System.out.println("The number is armstrong ");
}
else
{
System.out.println("The number is not armstrong");
}
}
}
Q-6.Write a program to print Febonacci series till n
terms.
import java.io.*;
class febonacci
{
public static void main(String args[])
throws IOException
{
BufferedReader br=new BufferedReader(new InputStreamReader-
(System.in));
System.out.println("Enter the no. of terms");
int n=Integer.parseInt(br.readLine());
int i,a=0,b=1,f;
System.out.println(a+“ ”+b);
for(i=3;i<=n;i++)
{
f=a+b;
System.out.println(“series is”+f);
a=b;
b=f;
}
}
Q-7.Write a program to find Factorial of any number.
import java.io.*;
class factorial
{
public static void main(String args[])
throws IOException
{
BufferedReader br=new BufferedReader(new InputStreamReader-
(System.in));
System.out.println("Enter a number");
int n=Integer.parseInt(br.readLine());
int f=1;
for(int i=1;i<=n;i++)
{
f=f*i;
}
System.out.println("The factorial value is"+f);
}
}
}
Q-8.Write a program to print the following Pattern:

Class pattern 1
{ 10
public static void main(String args[]) 101
{ 1010
for(int i=1;i<=5;i++) 10101
{
for(int j=1;j<=i;j++)
{
If(j%2==0)
{
System.out.println("0");
}
else
{
System.out.println("1");
}
}
}
}
}
Q-9.Write a program to print the following Pattern:
Class pattern2 1
{ 23
public static void main(String args[]) 456
{ 7 8 9 10
int i,j,k=1; 11 12 13 14 15
for(i=1;i<=5;i++)
{
for(j=1;j<=i;j++)
{
System.out.print(k);
}
k++;
System.out.println();
}
}
}
Q-10.Write a program to check whether the number is
Prime or Not.
import java.io.*;
class prime
{
public static void main(String args[])
throws IOException
{
BufferedReader br=new BufferedReader(new InputStreamReader-
(System.in));
System.out.println("Enter a number");
int n=Integer.parseInt(br.readLine());
int s=0,i;
for(i=1;i<=n;i++)
{
If(n%i==0)
{
S=s+1;
}
}
if(s==2)
{
System.out.println("The number is prime ");

}
else if(s>2)
{
System.out.println("The number is not prime");
}
}
}

Q-11.Write a program to evaluate the following Series


till n terms:(5)+(5+10)+(5+10+15)+…………n?
import java.io.*;
class series
{
public static void main(String args[])
throws IOException
{
BufferedReader br=new BufferedReader(new InputStreamReader-
(System.in));
System.out.println("Enter the no. of terms");
int n=Integer.parseInt(br.readLine());
int i,j,s=0,k;
for(i=1;i<=n;i++)
{
k=5;
for(j=1;j<=i;j++)
{
s=s+k;
k=k+5;
}
}
System.out.println(“series is”+s);
}
}

Q-12.Write a program to check whether the character is


Uppercase,lowercase or digit.
import java.io.*;
class check
{
public static void main(String args[])
throws IOException
{
BufferedReader br=new BufferedReader(new InputStreamReader-
(System.in));
System.out.println("Enter the character");
chara= (char)(br.read);
if(a>=65 && a<=90)
{
System.out.println(“The character is uppercase”);
}
elseif(a>=97 && a<=122)
{
System.out.println(“The character is lowercase”);
}
elseif(a>=48 && a<=57)
{
System.out.println(“The character is digit”);
}
}
}
Q-13.Write a function oriented-program to input
principal,rate and time & find SimpleInterest.
import java.io.*;
class simple
{
public void interest(double p,double r,double t)
{
double si;
si=(p*r*t)/100;
System.out.println("Simple Interest is"+si);
}
public static void main(String args[])
throws IOException
{
BufferedReader br=new BufferedReader(new InputStreamReader-
(System.in));
System.out.println("Enter the principle");
doublep=Double.parsedouble(br.readLine());
System.out.println("Enter the rate");
doubler=Double.parsedouble(br.readLine());
System.out.println("Enter the time");
doublet=Double.parsedouble(br.readLine());
simple ob=new simple();
ob.interest(p,r,t);
}
}

Q-14.Write a function oriented-program to input


principal,rate and time & find CompoundInterest.

import java.io.*;
class compound
{
public void interest(double p,double r,double t)
{
double ci;
ci=Math.pow((1+r/100), t);
System.out.println("Compound Interest is"+ci);
}
public static void main(String args[])
throws IOException
{
BufferedReader br=new BufferedReader(new InputStreamReader-
(System.in));
System.out.println("Enter the principle");
doublep=Double.parsedouble(br.readLine());
System.out.println("Enter the rate");
doubler=Double.parsedouble(br.readLine());
System.out.println("Enter the time");
doublet=Double.parsedouble(br.readLine());
compound ob=new compound();
ob.interest(p,r,t);
}
}

Q-15.Write a function oriented-program to find the


Roots of Quadratic-Equation.

import java.io.*;
class quadratic
{
public void equation(double a,double b,double c)
{
double d,r1,r2;
d=b*b-4*a*c;
if(d>0)
{
r1= -b+Math.sqrt(d/(2*a));
r2= -b-Math.sqrt(d/(2*a));
}
else if(d==0)
{
r1= -b/(2*a);
r1=r2;
}
else if(d<0)
{
System.out.println("Roots are imaginary or complex");
}
}
public static void main(String args[])
throws IOException
{
BufferedReader br=new BufferedReader(new InputStreamReader-
(System.in));
System.out.println("Enter the value of A");
doublea=Double.parsedouble(br.readLine());
System.out.println("Enter the value of B");
doubleb=Double.parsedouble(br.readLine());
System.out.println("Enter the value of C");
doublec=Double.parsedouble(br.readLine());
quadratic obj=new quadratic ();
obj.equation(a,b,c);
}
}

Q-16.Write a function oriented-program to evaluate the


𝐱𝟐 𝐱𝟑
following Seriestill n terms: x+ + + ⋯𝐧
𝟐! 𝟑!
import java.io.*;
class evaluate
{
public void series(double x,int n)
{
int i,j,f;
double s=0;
for(i=1;i<=n;i++)
{
f=1;
for(j=1;j<=I;j++)
{
f=f*j;
}
s=s+Math.pow(x,i)/f;
}
System.out.println("Answer is"+s);
}
public static void main(String args[])
throws IOException
{
BufferedReader br=new BufferedReader(new InputStreamReader-
(System.in));
System.out.println("Enter the value of x");
doublex=Double.parsedouble(br.readLine());
System.out.println("Enter the no. of terms");
doublen=Double.parsedouble(br.readLine());
evaluatenew=new evaluate();
new.series(x,n);
}
}
Q-17.Write a function oriented-program to input total
electricity unit consumed & calculate total amount
as per condition given below:

Unit Consumed Rate per unit


First 50 unit 2/unit
Next 150 unit 3/unit
Next 200 unit 4/unit
Above 5/unit

import java.io.*;
class electriciy
{
public void consumed(int u)
{
double r,amt;
if(u<=50)
{
amt=u*2;
}
else if(u<=200)
{
amt=(50*2)+(u-50)*3;
}
else if(u<=400)
{
amt=(50*2)+(150*3)+(u-200)*4;
}
else
{
amt=(50*2)+(150*3)+(200*4)+(u-400)*5
}
System.out.println("Total amount is"+amt);
}
public static void main(String args[])
throws IOException
{
BufferedReader br=new BufferedReader(new InputStreamReader-
(System.in));
System.out.println("Enter the units of energy consumed");
doubleu=Double.parsedouble(br.readLine());
electricitybill=new electricity();
bill.consumed(u);
}
}
Q-18.Write a function oriented-program to input bill
Amount and calculate Discount&Total-amount
To be paid as per condition given below:

Bill Amount Discount %


Amount<=10000 2.5%
Amount<=25000 7.8%
Amount>25000 20%

import java.io.*;
class discount
{
public void amount(double amt)
{
double disc,totalamt;
if(amt<=10000)
{
disc=2.5;
}
else if(amt<=25000)
{
disc=7.8;
}
else if(amt<=40000)
{
disc=20;
}
disc=(amt*disc)/100;
totalamt=amt-disc;
System.out.println("Total amount is"+totalamt);
}
public static void main(String args[])
throws IOException
{
BufferedReader br=new BufferedReader(new InputStreamReader-
(System.in));
System.out.println("Enter the Bill Amount");
doubleamt=Double.parsedouble(br.readLine());
discounttotal=new discount();

total.amount(amt);
}
}
Q-19.Write a function oriented-program using return
statement to find Factorial of any number.
import java.io.*;
class factorial
{
public void number(int n)
{
int i,f=1;
for(i=1;i<=n;i++)
{
f=f*i;
}
return f;
}
public static void main(String args[])
throws IOException
{
int s;
BufferedReader br=new BufferedReader(new InputStreamReader-
(System.in));
System.out.println("Enter the number");
Int n=Integer.parseInt(br.readLine());
factorial obb=new factorial();
s=obb.number(n);
System.out.println("The factorial of number is"+s);
}

Q-20.Design a class Railway Ticket with following


Description:
Instance variables/data members:
String name: to store the name of the customer.
String coach: to store the type of coach customer want to travel
long mobno: to store customer’s mobile number.
int amt: to store basic amount of ticket.
int totalamt: to store the amount to be paid after updating the
original amount.
Member methods:
void accept() – To take the input for name,coach,mobile no. & amount.
void update()- To update the amount as per coach selected.
(extra amount to be added in the amount as follows)
Types of Coaches Amount
First_AC Rs. 700
Second_AC Rs. 500
Third_AC Rs. 250
Sleeper None
void display() – To display all details of a customer such as name,coach,
total amount and mobile number.

Write a main method to create an object of the class


and call the above methods.
import java.io.*;
class Railway
{
String name;
String coach;
long mobno;
int amt;
int totalamt;
void accept()throws IOException
{
BufferedReader br=new BufferedReader(new InputStreamReader-
(System.in));
System.out.println("Enter the Name");
name= br.readLine();
System.out.println("Entercoach");
coach= br.readLine();
System.out.println("Enter your mobile number");
mobno=Long.parselong(br.readLine());
System.out.println("Enter Amount");
amt=Integer.parseInt(br.readLine());
}
void update()
{
if(coach.equals(“First AC”)==True)
{
totalamt=amt+700;
}
else if(coach.equals(“Second AC”)==True)
{
totalamt=amt+500;
}
else if(coach.equals(“Third AC”)==True)
{
totalamt=amt+250;
}
else if(coach.equals(“Sleeper”)==True)
{
totalamt=amt+0;
}
}
void display()
{
System.out.println("name is"+name);
System.out.println("coach is"+coach);
System.out.println("mobile number is"+mobno);
System.out.println("amount is"+amt);
System.out.println("total amount is"+totalamt);
}
public static void main(String args[])
throws IOException
{
RailwayTicket rt=new RailwayTicket();
rt.accept();
rt.update();
rt.display();
}
}

CONCLUSION
This project file is a compilation of topic :
Java The case sensitive and about many
programs.
By this file I came to know about functions,
operators, expressions and looping statements,
etc, i.e. where they are used ,why they are
used and many other things.

Вам также может понравиться