Rasraj Bodake
Class:9C
Roll no. 19
Input in Java
SECTION B
Programs:
1.
Ans.
class Question1
{
void main(int a, int b)
{
int c,d;
c=a+b;
d=a*b;
[Link](“Sum=”+c);
[Link](“Product=”+d);
}
}
2.
Ans.
import [Link].*;
class Question2
{
static void main()
{
Scanner sc=new Scanner([Link]);
int a,b,c,d,e;
float av;
[Link](“Enter 5 integers:”);
a=[Link]();
b=[Link]();
c=[Link]();
d=[Link]();
e=[Link]();
av=(float)(a+b+c+d+e)/5;
[Link](“Average=”+av);
}
}
3.
Ans.
import [Link].*;
class Question3
{
static void main()
{
Scanner sc=new Scanner([Link]);
int a,b,c,d,e;
[Link](“Enter 2 integers:”);
a=[Link]();
b=[Link]();
c=a+b;
d=a-b;
e=c*d;
[Link](“Product=”+e);
}
}
4.
Ans.
import [Link].*;
class Question4
{
static void main()
{
Scanner sc=new Scanner([Link]);
int a,b,c,s;
float av,d;
[Link](“Enter 3 integers:”);
a=[Link]();
b=[Link]();
c=[Link]();
s=a+b+c;
av=s/3f;
d=s-av;
[Link](“Difference=”+d);
}
}
5.
Ans.
import [Link].*;
class Question5
{
static void main()
{
Scanner sc=new Scanner([Link]);
float p,r,t,si;
[Link](“Enter the principal:”);
p=[Link]();
[Link](“Enter the rate:”);
r=[Link]();
[Link](“Enter the time:”);
t=[Link]();
si=(p*r*t)/100;
[Link](“Simple Interest=”+si);
}
}
6.
Ans.
import [Link].*;
class Question6
{
static void main()
{
Scanner sc=new Scanner([Link]);
float l,b,a,p;
[Link](“Enter the length:”);
l=[Link]();
[Link](“Enter the breadth:”);
b=[Link]();
a=l*b;
p=2*(l+b);
[Link](“Area=”+a);
[Link](“Perimeter=”+p);
}
}
7.
Ans.
import [Link].*;
class Question7
{
static void main()
{
Scanner sc=new Scanner([Link]);
float r,a,pi=3.142f,c;
[Link](“Enter the radius:”);
r=[Link]();
a=pi*r*r;
c=2*pi*r;
[Link](“Area=”+a);
[Link](“Circumference=”+c);
}
}
8.
Ans.
import [Link].*;
class Question8
{
static void main()
{
Scanner sc=new Scanner([Link]);
float l,b,h,v,a;
[Link](“Enter the length:”);
l=[Link]();
[Link](“Enter the breadth:”);
b=[Link]();
[Link](“Enter the height:”);
h=[Link]();
v=l*b*h;
a=2*(l*b+b*h+h*l);
[Link](“Volume=”+v);
[Link](“Area=”+a);
}
}
9.
Ans.
import [Link].*;
class Question9
{
static void main()
{
Scanner sc=new Scanner([Link]);
float r,h,v,a,pi=3.142f;
[Link]( “Enter the radius:”);
r=[Link]();
[Link]( “Enter the height:”);
h=[Link]();
v=pi*r*r*h;
a=2*pi*r*r+2*pi*r*h;
[Link]( “ Volume=”+v);
[Link]( “Area=”+a);
}
}
10.
Ans.
import [Link].*;
class Question10
{
static void main()
{
Scanner sc=new Scanner([Link]);
int a,b,c,s;
[Link](“Enter the 3 integers:”);
a=[Link]();
b=[Link]();
c=[Link]();
s=a%10+b%10+c%10;
[Link]( “Sum of the last digits=”+s);
}
}
11.
Ans.
import [Link].*;
class Question11
{
static void main()
{
Scanner sc=new Scanner([Link]);
float f,c;
[Link]( “Enter temperature in farenheit:”);
f=[Link]();
c=((f-32)*5)/9;
[Link](“Temperature in celcius=”+c);
}
}
12.
Ans.
import [Link].*;
class Question12
{
static void main()
{
Scanner sc=new Scanner([Link]);
int sec,h,m,s;
[Link]( “Enter time in seconds:”);
sec=[Link]();
h=sec/3600; //finding hours
sec=sec%3600; //remaining seconds
m=sec/60; //finding minutes
s=sec%60; //remaining seconds
[Link]( “Time in hours=”+h);
[Link]( “ Time in minutes=”+m);
[Link]( “ Time in seconds=”+s);
}
}
13.
Ans.
import [Link].*;
class Question13
{
static void main()
{
Scanner sc=new Scanner([Link]);
float n;
int r;
[Link]( “ Enter a floating point number:”);
n=[Link]();
r=(int)(n+0.5f);
[Link](“Answer=”+r);
}
}
14.
Ans.
import [Link].*;
class Question14
{
static void main()
{
Scanner sc=new Scanner([Link]);
float n,t,r;
[Link]( “Enter a floating point number:”);
n=[Link]();
t=(int)(n*100+0.5f);
r=t/100;
[Link]( “Answer=”+r);
}
}
15.
Ans.
import [Link].*;
class Question15
{
static void main()
{
Scanner sc=new Scanner([Link]);
int a,b,c;
[Link]( “Enter 2 integers:”);
a=[Link]();
b=[Link]();
[Link](“Before Interchange:a=”+a+“and b=”+b);
c=a;
a=b;
b=c;
[Link](“After Interchange:a=”+a+“and b=”+b);
}
}
16.
Ans.
import [Link].*;
class Question16
{
static void main()
{
Scanner sc=new Scanner([Link]);
int h,m,s,sec;
[Link]( “Enter time in hours:”);
h=[Link]();
[Link]( “Enter time in minutes:”);
m=[Link]();
[Link]( “Enter time in seconds:”);
s=[Link]();
sec=h*3600+m*60+s;
[Link]( “Time in seconds:”+sec);
}
}
17.
Ans.
import [Link].*;
class Question17
{
static void main()
{
Scanner sc=new Scanner([Link]);
int a,b,c,s;
[Link]( “Enter 3 integers:”);
a=[Link]();
b=[Link]();
c=[Link]();
s=a-(-b)-(-c);
[Link]( “ Sum:”+s);
}
}
18.
Ans.
import [Link].*;
class Question18
{
static void main()
{
Scanner sc=new Scanner([Link]);
float p,s,a;
[Link](“Enter the perimeter of a square:”);
p=[Link]();
s=p/4; //finding the side
a=s*s;
[Link](“Area of the square is:”+a);
}
}
19.
Ans.
import [Link].*;
class Question19
{
static void main()
{
Scanner sc=new Scanner([Link]);
float l,b,a,p;
[Link](“Enter the length of the rectangle:”);
l=[Link]();
[Link](“Enter the area of the rectangle:”);
a=[Link]();
b=a/l; //finding the breadth
p=2*(l+b);
[Link](“Perimeter of the rectangle:”+p);
}
}
20.
Ans.
import [Link].*;
class Question20
{
static void main()
{
Scanner sc=new Scanner([Link]);
float bp,da,hra,pf,np,gp;
[Link](“Enter the basic pay:”);
bp=[Link]();
da=25/100f*bp;
hra=15/100f*bp;
pf=8.33f/100*bp;
np=bp+da+hra;
gp=np-pf;
[Link](“Gross Pay:”+gp);
}
}
21.
Ans.
import [Link].*;
class Question21
{
static void main()
{
Scanner sc=new Scanner([Link]);
float l,b,p,s,a;
[Link](“Enter the length and breadth of the rectangle:”);
l=[Link]();
b=[Link]();
p=2*(l+b); //finding the perimeter
s=p/4; //finding the side of the square
a=s*s;
[Link](“Area:”+a);
}
}
22.
Ans.
import [Link].*;
class Question22
{
static void main()
{
Scanner sc=new Scanner([Link]);
int n,s;
[Link](“Enter an integer:”);
n=[Link]();
s=-n;;
[Link](“Sign changed:”+s);
}
}
23.
Ans.
import [Link].*;
class Question23
{
static void main()
{
Scanner sc=new Scanner([Link]);
float m1,m2,m3,m4,m5,agg,per;
[Link](“Enter the marks:”);
m1=[Link]();
m2=[Link]();
m3=[Link]();
m4=[Link]();
m5=[Link]();
agg=m1+m2+m3+m4+m5;
per=agg/500*100;
[Link](“Aggregate:”+agg);
[Link](“Percentage:”+per);
}
}
24.
Ans.
import [Link].*;
class Question24
{
static void main()
{
Scanner sc=new Scanner([Link]);
float tsp,tp,tcp,cp;
[Link](“Enter the total selling price:”);
tsp=[Link]();
[Link](“Enter the total profit:”);
tp=[Link]();
tcp=tsp-tp; //total cost price
cp=tcp/15; //cost price of one item
[Link](“Cost Price of one item:”+cp);
}
}