Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

Solutions to Exercise on Java Basics

Day #1
Answer #1.
1.b) literal
2.c)false
3.b)char type literal
4.a)' '
5.a)String variable
6.a) 65-90
7.a)a*2 and a^2
8.a) boolean m = true

Answer #2
1) double pi = 22.0/7;
2. a) double d = 35.0012;
b) double d = 2*1.414;
c) double x = 435.0;

3) double a = 45.1;
double b = 15.05;
double c = 92;
double sum = 0;
sum = (a+b)*c/2;
System.out.println("The answer: "+sum);

4.a) int
b) long
c) double

5) float
String

6) n = 66
ch = 'B'

7.i) Standalone applications and Java applets


ii) java.lang

8) There are two types of type casting namely:


(i) Explicit type casting e.g. float area = (float)Math.pow(s*(s-a)*(s-b)*(s-c));
(ii) Implicit type casting e.g. float sum = 5; //sum will store 5.0f through implicit type casting

9.i) 4 bytes
ii) character type
iii) Assignment statement
iv) -2

10.i) Correct already.


ii) To run a Java program,we need to right click the compiled class
1
iii) Correct statement
iv) The Selection statements of Java are:
(i) if..else if..
(ii) switch-case

11.i) byte, short, int, long


ii)System.out.println("\"Hello Madam! It's Ravi's birthday today.\"");
iii) Yes, we can write.
iv)a)int
b)String
c)char
d)double
e)boolean

v)a) Valid
b) Valid
c) Invalid; Reason: A variable cannot start with a number
d) Invalid;cannot have"." Invalid. A Dot cannot be used in a variable.
e) Valid

You might also like