Академический Документы
Профессиональный Документы
Культура Документы
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");
}
}
}
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);
}
}
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);
}
}
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:
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);
}
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.