0% found this document useful (0 votes)
25 views

Final Term Worksheet Comp

1. The document discusses various mathematical functions in Java like Math.ceil(), Math.floor(), Math.round(), Math.abs(), Math.sqrt(), Math.pow(), Math.max(), Math.min() and provides examples of their usage. 2. It asks questions about the output and values stored in variables after applying different mathematical functions on values like finding minimum, maximum, absolute value, square root etc. 3. The questions cover concepts like rounding, ceil, floor functions, random number generation in a range, converting a number to its closest integer etc.

Uploaded by

pranavsandeep17
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
25 views

Final Term Worksheet Comp

1. The document discusses various mathematical functions in Java like Math.ceil(), Math.floor(), Math.round(), Math.abs(), Math.sqrt(), Math.pow(), Math.max(), Math.min() and provides examples of their usage. 2. It asks questions about the output and values stored in variables after applying different mathematical functions on values like finding minimum, maximum, absolute value, square root etc. 3. The questions cover concepts like rounding, ceil, floor functions, random number generation in a range, converting a number to its closest integer etc.

Uploaded by

pranavsandeep17
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 15

SCHOOL

NATIONAL
GOPALAN
Moth
functions,
Methods 63.0
BENGALURU
WHITIEFIELD,
Mathematical
Library d=Math.ceil(Mat
functions:
44$
5.Mathematical 22 -1408
-Ts
k)Math.round(-18.51)
Math.min(13,14)
h)Math.max(22,
a=Math.max(a%100,a/100
--2/.0 i)Math.min(Math.floor(2.9),2.5)2-0
following different
1Math.round(Math.abs(-0.5))
i) System.out.print
D=
63.0
following -7
f)Math.max(-17,-19)
CH
.0
a)
/.0
Matd) h1.Math.round(0.5)
Math.ceil(-4.2) fe)loor(-20.
c)Math.pow(2,0) O
8.
10)
g)Math.ceil(7.8)
3.2
)Math.sqrt(10.24)
a 4the
m)Math.abs(99.4) for
used System.out.println("A="+
4 of a)
Math.sqrt();
doube
Aoubec)Math.ceil();
doubk
b)Math.pow();
d)Math.floor();
odse e)Math.round():
it double
b)Math.abs(-4) type
the is
for return that
-62.4;
output class
the a=948;int
:IX
CLASS the C=
:NAME Give 2.Predict 5.double
3.Name
1. 4.int
6.What will be the output of following code?
double b= -15.6;
double a=Math.round(Math.abs(b));
System.out.printin("a="+a); ar l6
7.Give output for the following segment :
double x=2.9,y=2.5;
System.out.printin(Math.min(Math.floor(x), y));
System.out.printin(Math.max(Math.ceil(x),y));
8.What are the final values stored in variable x and y below?
double a= -6.35;
double b=14.74;
double X=Math.abs(Math.ceil(a)); 6
double y=Math.round(Math.max(a,b)); 15.0
9.What will be the final values be stored in variables
when executed?
double a=-3.5;
double b= -25.0;
double p=Math.abs(Math.floor(a)); 40
double q=Math.sqrt(Math.abs(b)); 50
10.What will be the value of num given in following
statements
int min=1,max=10;
int range=max-min+1;
int num=(int)(range*Math.random()+min);
11. Write the equivalent java
statements for the following ,by using the
functions: mathematical
a) Print the positive value of -999.
b)Store the value -3375 in a variable and print its
cube root. in x-3575
c) Store the value 999.99 in a
variable and convert it into its closest integer that ic
greater than or equal to 999.99.
Hint:Triangle2/Write Smallest
numberSampl
34e Sample Hinsmal
t: lest 1.Write Pg12.
(a) (c) (b) (entered
a) 3.Write noWrite
TakedisplayBiology. 4.In Cube Square
Absolute h Use
Random Input: of a
examination, an
PROGRAMS163(Q4.
.3)
by a = by a Output: Mat h.min() thpre ogram
Physics, the of program Vp2+ takingprogram mat hematical
Write the root value the 87, three
marks numbers b² it
number of user: Greatest 65, in. n
Chenmistry. in
program a the of to perpendicular and
34numbers. r(x).at.
in Java
input
S.oJavaph{ia-375;
have
you
the to equation
rounded-off between number
number to Number Math.max( input
three
the
and in a calculate for
Java number
0 and 87 followingthe
Biology form. to
appeared (zero) )
and base and numbers
marks calculate and evaluate as
display
for 1 inputs.
as the three (one). and
inputs. average the the
subjects display
results hypotenuse
mark i.e. based
greatest
obtainedPhysics, of
on a
the Right-Angled
Chemi
and stry and
number the
finally
and
to calculate theradius of acircle byusing the formula:
5.You want
Area= (22/7) * r2; where r= radius of a circle
Hence the radius can be calculated as:
r=V(7 * area) /22)
as
Write a program in Java to calculate and display the radius of a circle by taking area
an input.

6.Program to compute the perimeter andare of a triangle with its three sides given as
a,b,c using the following formula
Perimeter=a+b+c
Use Heron's fornula with

sides ab and c

a+6c

Area=
/a(s- a)(s b){8 c)
7.Program to calculate and display the final
velocity by taking initial
,acceleration and the distance covered as input.
V2=u2+2as
where usinitial velocity
velocity
a=acceleration and the distance
covered as inputs.
GOPALAN WUTEFIEL),
NATIONAL BLNGALURU
SCHOOl
NAME :
CLASS :1X CH 5.0perators in java

1.Consider thefollowing snippet:


int i=10;
int n=i++%5;
What are the values of iand n after the code is executed? i* li, n - 0
2.If int a=5, what would be the value of a and b after executing two different
expressions?
i)b=a++ ta; 10 ii) b=+tata; 19

3.int x=0, y=0,z=0;


x=(+txty--)*z++;
What will be the value of "x"after execution? O

4.Arrange theoperators in order of precedence from highest to lowest:


a)< b)= c)++ d)&&
5.What would be the output of following code:
int a,b,c;
a=10;
b=15;
c=25;
i)System.out.printn(c>b &&b>a); Tree
i)System.out.printin(a<b); Irue
i)System.out.printin(c>a||b<c); ru
6.What will be the final value of the
i) int k=16,g=6,p=15; variables in the folowing code:
p-= --k - --g; 5
ii)double p=17.12,q=0.08,r=0;
rt= +tp - ++q; 704
iilint s=99,q=50,r=2;
r*=++S - q--; /oO
87.Consider the following code snippet:
float x=8.25f;
int y;
y-(int)x;
What are the values of x and y?
8ÁWhat is the use and syntaxof ternary operator? 74

ii) Evaluate the value of n,if value of p=5,q=19


int n=(q-p)>(p-q)?(q-p): (p-q) (4
9.Give the output of the following expression:
i) at= af + tta + a +a:-; when a=5

346 4356
i) x+=x¢+ + ttx +X; when x=4; a0
i)p+=(-p+5)*(p++)*(r/2) ;when p=7and r=11
iv) q*=5+(--a)*(g++)+10;when q-9 7 370

10.Write java expression for the following:


|3x +x2 ii) a²+b
3a60
iv) y=2(lb+bh+lh)
a+b iilz= 5x²+2y
2ab x+y

11.What is the output of the folowing program snippet:


char x= a'; int m;
m=(x==a')? 'a':"A'
System.out.prntin("m="+m);
(12) Answer the following maq7
a.Distinguish between unary,binary and ternary operator with examples for each of
them.
b.What is type conversion injava ?How is an implicit conversion different from explicit
conversion?
c)What is meant byprecedence and associativity of an operator?
x13.What are the type of casting shown by the following examples. Also write the
resultant data type?
i)double x=15.2;
int y=(int)x;
i)int x=12;
long y=x;
ii) char c=(char)120;
iv) int x=t';
14.Rewrite the following using ternary operator:it z=
int x=2; String str;
if(x%2==0) Stving st (xo2r :0)?
System.out.println("EVEN");
else

System.out.println("ODD");
Syitm,outprit "EvtN
n(tye ODD

X15.What does the following mean?


a) Employee staff=new
Employee();
816.Write a java statement
i)to create an object mp4 of
class digital. (02
i)to create an object
keyboard ofclass
computer
GOPALAN NATIONAL SCHOOL
WUITEFIRLD, BENGALURU
NAME:
CLASS :1X CH 6.Input in Java

programming Interface
1.What is mean by a package?Name any two Java application
packages.
2.What are delimiters?

3.Name the following:


package in your program? hpe
a) Which keyword do you use to include a
b) Default delimiter used in the Scanner class.tan
package would you import to display the date and time? ut
c)Which
package would you import for the scanner class? E t
d)Which
4.Name the type of error

a)Math.sqt(36): Sye
b)int a;b;c; Syree
c)int a==b+c; Syrtt
operation should be division. Llca
d)Multiplication operator is used when the
comments and write its name?
5.Which of the followings are valid
i) /* comment */ vai, Mati line
in)/*comment avai
ii)//comment vaa,sigleine
iv)*/comment*/

class
6.Name the method of scanner
from the standard input device. netLt)
a) is used to input an integer data
standard input device. etShig nat)
b)is used to input a string datafrom the
standard input device. nent ). chrt
clis used to input a character data from the
7.Write line of code that
named
objectsean
a) Creates ascannerSeannan scan and read double value in dblvariable
<new Seannen CSytindn;
program
bl toinclude allclasses present in the java .util package into your
what is the difference between the scanner class element next() and nextLine()?
9.Write a program to computethe Time of period (T) of.a simple pendulum

following formula:
Input the value of L(Length of pendulum )and g
T=2n//g
Scannerclass.
leravity
methods ,to read and displav st
10. Write aprogram in java ,using the scanner
following details.
Name-as a string data type.
RollNumber -as an integer data type
Marks in 5 subjects -as a float data type
Compute and display percentage of marks.
1Write a program by using class 'Employee' to accept Basic pay of an
employee.Calculate the allowance/deduction as given below.Finally find and print the
Gross and Net pay.
Dearness Allowance(DA) :30% of Basic pay
House Rent Allowance(HRA) :15%of Basic pay
Provident Fund(PF) :12.5% of Basic pay
Gross Pay =Basicpay+DA+HRA
Net Pay= Gross Pay-PF

12. Ashopkeeper offers


30%discount on purchasing articles whereas the other
shopkeeper offers two successive discounts 20% and 10% for purchasing the same
articles .Write a program to compute and display the
article as the input. discounts.Take the price of an
Hint :Successive
discount=MPx 100-d1 100-d2
x
100 100
13.Write a program tocalculate simple
values: interest and the Total Amount with the
i) Principle :Amount :20000
given
ii)Rate :8.9%
ii)Time :3 years
Hint :Sl=(p*r*t)/100
14.Write a program in java that accepts the
the corresponding
number of
seconds as input and converts them into
below: hours,minutes and seconds.A sample output is shown
Sample Output :Enter Total
1 Hour(s) 23 Seconds: 5000
(Minute(s) 20 Second(s)
Hint: hr=sec/3600
Min=(sec%3600)/60
Sec=sec%60
1s)Write a program in Java to input the temperature in Fahrenheit,convert it into
celcius and display the value.
Sample output: Enter temperature in Fahrenheit :176
176Fahrenheit=80.0 degree celcius
Hint:F=9/5C+32
C=5/9(F-32)
numbers after swapping
16.Write a program to input twO unequal numbers.Display the
their values in the variables without using a third variable.
Sample output : a=23,b=25
a=25,b=23
earns 20% profit on one
17.Ashopkeeper sells two calculators for the same price.He
cost price of the
and suffers a loss of 20% on the other.Write a program to find his total
calculators by taking selling price as input.
Hint:cp= (SP *100 ) /(100 + percentage profit), when profit
.CP=(SP 100 )/(100- percentage loss ),when loss

**** k *
Class

SCHO)OL
NATIONAL
GOPALANWWPLD BENGALUR
S
an
NAME:
CLASSX CH9.conditional constructs in java |en

1.Write the following snippct using ternary operator:


a) ifincome<1000)
tax 0;
clsc
tax-12: e

b)iflp>=4750)
k-p*s/100;
else
k-p*10/100;
c) ifla>b)
if(a>c)
ga;
else
g=c;
if(b>c)
g-b;
else
g-C;

2.Rewrite the following statement using if-else:


a) net-(salary>10000)2salary-(8.33/100*salary:salary-(S/100)*salary
b) s-(a+b<c |ate<=b|| bte<ra)?"Triangle is not possible":*Triangle is possible";
3.Predict the output
a) int x=l;y=1;
if(n>0)
{
XFX+1;
yy+1;

What willbe the value of x and y ,if n


assumes a value ()I
b) int a-20,b=15; (ii)0?
if(a>10)
at+;
b+t+;}
System.out.println(a+","+b);
Income Tax in

in
Taxable income(TI)
* 10%
than or cqual to (TI- 1,60,000)
2.50,000 and less
More than
S,00,000 20% +
(TI -5,00.000) *
or equal to
5,00,000 and less than 34,000
More than
10,00,000
30% +
(TI - 10,00,000)*
94,000
Morethan 10,00,000
income of a person. If the age is
the name, age and taxable age is less than
Write a progranto inputdisplay the message "Wrong Category". If the with the
more than 60 years then compute and display the income tax payable along
or equal to 60 yearsthen table given abOve. in
name of tax payer, as per the certain sumof money under "Term Deposit' scheme
6.An employee wants to depositprovided the tariff of the scheme, which is given below:
Syndicate Bank. The bank has
Rate of Interest
No. of Days
5.5%
Up to 180 days

181 to 364 days 7.5%

Exact 365 days 9.0%

More than 365days 8.5%

Write a program to calculate the maturity amounttaking the sum and number of days
as inputs.

7.A company announces revised Dearness Allowance (DA) and Special Allowances
(SA)for their employees as per the tariff given below:
Basic Dearness Allowance (DA) Special Allowance (SA)
Up to ?10,000 10% 5%
10,001 -20,000 12%
8%
{ 20,001 -30,000
15%
10%
730,001 and above 20%
12%
Write aprogram to accept nameand 3Basic Salary (3S) of an employee. Calculate and
display gross salary.
Gross Salary =Basic + Dearness Allowance +Spccial Allowance
Print the information in the given format:
Name Basic DA Spl. Allowance Gross Salary
XXX XXX XXX XXX

8.Using a switch case statemcnt, write a menu driven program to convert a given
temperature from Fahrenheit to Celsius and vice-versa.
For an incorrect choice, an appropriate message should be displayed.
Hint: c = 5/9*(f-32) and f=1.8*c+32
9.The volume of solids, viz. cuboid, cylinder and cone can be calculated by the
formula:
Volume of a cuboid (v = 1*b*h)
Volume of a cylinder (v = *r*h)
Volume of a cone (v =(1/3)*n*r*h)
Using a switch case statement,write a program to find the volume of different solids
by taking suitable variables and data types.
10.The Simple Interest (SI) and Conmpound Interest (CI) of asum (P) for a given time
(T) and rate (R) can be calculated as:
(a) SI =(p *r*t)/ 100 (b) CI =P* ((1 +(R/100))" - 1)
Write a program to input sum, rate, time and type of Interest ('S' for Simple
and 'C' for Compound Interest). Calculate and display the sum Interest
11. Write amenu driven program to calculate: and the interest earned.
Area of acircle = p*r2, where p (22/7) [15]
Area ofa square = side*side

Arca of a rectangle = length*breadth


Enter 'c' to calculate area of circle, 's' to
of rectangle. calculate area of square and 'r to calculate area

*****
GOPALAN NATONAL SCHOOL
Name: WORKSHEET
Class : CH:NESTED FOR LOOP(JUMP STATEMENTS)

I)Write the output for the following:

a) int x,y;
for(x=1;x<=5;x++)

for(y=1;y<5;y++)

if(x==4)
break;
System.out.print(y):

System.out.println(0;

b. int i,j;
for(i=10;i>=5;i--)

forlj=5;j<=i;j++)
if(i*j<40)
continue;
System.out.print(j):

System.out.printin);

c. int i,j;
for(i=1;i<=5;i++)

for(j=1;j<=3;j++)
if(i%2==0)
continue;
System.out.print(i*it" ");
d.int i,j: 4
for(i=1;i<-5;i++) 8
12
{
forlj=1;j<=3j++)
System.out.prinln(ii):
if(i==)
break;
}

e. for(int i=l;i<=5;i++)

for(int j=1;j<-3;j++)
System.out. print(i"j);

if(i>2)
break;
System.out.print("*****);
}

f. for(int i=1;i<=5;i++)

for(int j=1;j<-i;jt+)

if(i==4) jl 23 123
break; 5 s123H5
System.out.print(j);
System.out.println ();

8. for(int i=1;i<=5;i++)

for(int j=1;j<-3;j++)
if(i"j>=10)
continue;
System.out.print(i*j+" );
executed?
V)What
II)Study h.
or(int
;i<5;it+) ctr=0;
int
System.out.printin(number);
=2)for(intnumber-(int)Math.random()*10); W)Anal
i=3;i<=4;it+)
for(inta) yse
j=0;j<2;j++)
int for(int
i=0;i<3;i++)
for(int i) i) it(i=2) for(int
is b) sampleMethod()
public for(int
System. the j-1;j<«3;j++)
for(icontinue,
nt
void out.printin("WIN");
the Whata)How System.out.println(""):j=2;j<i;j++) System.out.print(i°j ";
"
final the i=
many
method Write How 1,
is given ix=5;+)
value the themany
times and output program
of
range times
ctr the answer
of of
when possible inner does segment
the the
the
the loop given program inner
and
iteration values does
questions:segment loop answer
stored
execute?
process wil the
in execute?.
the
following
given
variable
below questions
number?

You might also like