0% found this document useful (0 votes)
15 views3 pages

Programming Language Assignmet 1

Program usefully

Uploaded by

sh5nnp6zdy
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)
15 views3 pages

Programming Language Assignmet 1

Program usefully

Uploaded by

sh5nnp6zdy
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

Expression & Assignment Worksheet for Java

You may only use calculators for arithmetic. Do not enter entire expressions. There will be no calculators
permitted for the test/s.
*The answers for 1-11 QUESTIONS IS IN THE NEXT PAPER*

1. Define a variable. 14. Given the following declarations, what is the


2. Define an identifier. result of each of the assignments?
3. A variable can store ____ value/s of its type. int w = 5, y = 9, z = 2;
4. Define a constant.
5. Define an expression. a. z = w * y;= 45
6. Name the four integer data types. z += y;= 11
How many bytes are allotted to each? b. y /= z;=4
7. Name the two floating point data types. c. y %= z; =1
How many bytes are allotted to each? d. y += y++; =18
8. What is an escape sequence? e. y += --y; =17
9. What is operator precedence? 15. Given the following declarations, what is the
10. Why are widening conversions safer than narrowing result of each of each output?
conversions? char a = 'a', b = 'B';
11. What does the new operator accomplish? char c = ' ', d;
12. Given the following declarations, what is the result string s = "This is fun.";
of each of the expressions? int e;
int w = 2, y = 7, z = 12;
System.out.println
a. w * z =24 a. ("a = " + a); a=a
b. w * z + y = 31 b. ("a = " + 'a');a=a
c. w * -z = -24 c. (a + b); 163
d. w * --z + y++ =29 d. (s); This is fun.
e. w * z-- + ++y =32 e. (s.length());12
f. w + z * y =86
g. w – y + z =7 16. Convert the algebraic equations to Java
h. (w + y) * z =108 equations.
i. y / w =3
j. y / z =0 a. SA = 4rr 2 =4 * PI * r * r;
k. w % y =2 4
b. 𝑉 = 3 𝜋𝑟𝑟 3 = 4 * PI * r * r * r /3 ;
l. y % w =1
13. Given the following declarations, what is the result c. A = s(s − a )(s − b )(s − c )
of each of the expressions? =math.sqrt(s*(s-a)*(s-b)*(s-c))
double w = 12.9, y = 3.2; d. D = ( x2 − x1 ) 2 + ( y2 − y1 ) 2 =
double z = 12.2;
math.sqrt((x2-x1)*(x2-x1)+(y2-
y1)*(y2-y1));
a. w / z =1.057377049180328
b. z / w =0.945736434108527 − b  b 2 − 4ac
e. X =
c. w / z – y = −2.142622950819672 2a
d. w – z * y =-26.14
e. (w – z) * y =2.2400000000000033
f. z / y / w =0.295542635658915 X1(-b+ Math.sqrt(b*b-4*a*c)) /(2*a);
g. z / (y / w)=49.18125 X2(-b - Math.sqrt(b*b-4*a*c)) /(2*a);
h. y % z =0.7000000000000011
Hint: Write two equations
Answers

Q1: A variable is a named memory location


capable of storing data

Q2: Identifier is a name used to identify a


variable, function, class, module or any other
user- defined item.

Q3: it can store Single value of its type

Q4 : constant is the opposite of a variable and


it’s a value that never change

Q5: An expression is a combination of terms


that are combined by using mathematical
operations

Q6 : integer data types:

Name of Number of
Date types bytes
1-byte 8 bits
2-short 16 bits
3-int 32 bits
4-long 64 bits

Q7: floating point data types:

Name of Number of
Data types bytes
1-float 32 bits

2-double 64 bits

Q8:An escape sequence is used to include


reserved symbols in output

Q9:Precedence is the order in which the computer


will execute operators

Q10: in widening conversions data can’t be lost, but


in narrowing it can be lost

Q11: The new operator creates a new instance (an


object) of the specified class

You might also like