Professional Documents
Culture Documents
Engineering
import java.io.*;
class njp2
{
public static void main(String arg[])throws IOException
{
InputStreamReader obj=new InputStreamReader(System.in);
BufferedReader br=new BufferedReader(obj);
int ch,r,l,w;
float pi=3.14f;
double area;
case 2:
{
System.out.print("Enter length of Rectangle:");
l=Integer.parseInt(br.readLine());
System.out.print("Enter Width of Rectangle:");
w=Integer.parseInt(br.readLine());
area=l*w;
System.out.println("Area=" + area);
break;
}
}
}
}
import java.io.*;
import java.lang.Math.*;
delta=b*b-4*a*c;
if(delta<0)
{
System.out.println("There are No Solution");
}
else if(delta==0)
{
System.out.println("There is one solution of equation");
ans1=b/(2*a);
System.out.println("Answer :"+ans1);
}
else
{
System.out.println("Following are two Solution of Equation");
ans1=-b+Math.sqrt(delta)/(2*a);
ans2=-b-Math.sqrt(delta)/(2*a);
System.out.println("Answer 1 :"+ans1);
System.out.println("Answer 2 :"+ans2);
}
import java.io.*;
class njp4
{
public static void main(String arg[]) throws IOException
{
double f,c;
System.out.println("For Convert Temp in celsius to Fahranhit press 1");
System.out.println("For Convert Temp in Fahranhit to celsius press 2");
InputStreamReader obj=new InputStreamReader(System.in);
BufferedReader br=new BufferedReader(obj);
System.out.print("Press Ur Choice:");
int ch;
ch=Integer.parseInt(br.readLine());
switch(ch)
{
case 1:
{
System.out.print("Enter Temp in celsius:");
c=Double.parseDouble(br.readLine());
f=1.8*c+32;
System.out.println("Temp in Fahranhit is : "+f);
break;
}
case 2:
{
System.out.print("Enter Temp in Fahranhit:");
f=Double.parseDouble(br.readLine());
c=(f-32)/1.8;
System.out.println("Temp in celsius is :"+c);
}
}
import java.io.*;
class njp5
{
public static void main(String arg[]) throws IOException
{
int no;
InputStreamReader obj=new InputStreamReader(System.in);
BufferedReader br=new BufferedReader(obj);
System.out.print("Enter Number:");
no=Integer.parseInt(br.readLine());
if(no%2==0)
{
System.out.println("Number is Even");
}
else
{
System.out.println("Number is Odd");
}
}
}
class njp6
{
public static void main(String arg[]) throws IOException
{
int year;
InputStreamReader obj=new InputStreamReader(System.in);
BufferedReader br=new BufferedReader(obj);
System.out.print("Enter Year:");
year=Integer.parseInt(br.readLine());
}
}
class njp7
{
public static void main(String arg[])throws IOException
{
int a,b,ans;
System.out.print("Enter Operator:");
char op;
op=(char)br.read();
switch(op)
{
case'+':
{
ans=a+b;
System.out.println("Answer="+ans);
break;
}
case '-':
{
ans=a-b;
System.out.println("Answer="+ans);
break;
}
case '*':
{
ans=a*b;
System.out.println("Answer="+ans);
break;
case '/':
{
ans=a/b;
System.out.println("Answer="+ans);
break;
}
case '%':
{
ans=a%b;
System.out.println("Answer="+ans);
break;
}
default:
{
System.out.println("Wrong Choice");
}
}
}
}
8. Write a program to print the Fibonacci series up to n
numbers.
import java.io.*;
class njp8
{
public static void main(String arg[])throws IOException
{
int i,n,a,b,c;
InputStreamReader obj=new InputStreamReader(System.in);
BufferedReader br=new BufferedReader(obj);
System.out.println("Eneter How many no?:");
n=Integer.parseInt(br.readLine());
for(i=0;i<n;i++)
{
c=a+b;
a=b;
b=c;
System.out.println(c);
}
}
}
9. Display all the prime numbers within a given range.
import java.io.*;
class njp9
{
public static void main(String arg[])throws IOException
{
int start,end;
InputStreamReader obj=new InputStreamReader (System.in);
BufferedReader br=new BufferedReader(obj);
for(int j=start;j<end;j++)
{
boolean prime=true;
for(int i=2;i<j/2;i++)
{
if(j%i==0)
}
if (prime)
{
System.out.println(j +" is Prime Number");
}
}
}
}
10.Write a program to calculate the square and cube of
the given number until the user enters the negative no.
*
**
***
****
*****
import java.io.*;;
class njp11
{
public static void main(String arg[])
{
int n,j,p,no=5;
for(n=0;n<no;n++)
{
for(p=no-1;p>n;p--)
{
System.out.print(" ");
for(j=0;j<=n;j++)
{
System.out.print("* ");
}
System.out.println();
}
}
}
class njp12
int i,j;
for(i=0;i<3;i++)
for(j=0;j<3;j++)
a[i][j]=Integer.parseInt(br.readLine());
System.out.println();
for(i=0;i<3;i++)
for(j=0;j<3;j++)
b[i][j]=Integer.parseInt(br.readLine());
for(i=0;i<3;i++)
for(j=0;j<3;j++)
for(int k=0;k<3;k++)
c[i][j]=c[i][j]+a[i][k]*b[k][j];
for(i=0;i<3;i++)
for(j=0;j<3;j++)
System.out.print(" "+c[i][j]);
System.out.println();
int i=0;
System.out.println("Enter Character:");
do
s[i]=(char)br.read();
i++;
}while(s[i-1]!='z');
int len=i-1;
int j;
boolean njp=true;
for(i=0,j=len-1;i<len;i++,j--)
njp=false;
break;
if(njp==true)
System.out.println("String is PALANDROM");
else