0% found this document useful (0 votes)
11 views2 pages

Programming_techniques_Assignment No. 02

Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
0% found this document useful (0 votes)
11 views2 pages

Programming_techniques_Assignment No. 02

Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 2

UNIVERSITY OF RUHUNA

DEPARTMENT OF MATHEMATICS
B.Sc. honours in financial mathematics and industrial statistics
MSF1123: PROGRAMMING TECHNIQUES

Assignment No : 02 Semester I, 2023


Submit the answers on or before 10.00am on 13/10/2023

1. Write and execute following Java programs then check the outputs.

(a) public class testOperator1 {


public static void main(String[] args) {
int x = 10;
int y = 20;
int result = x + y;
System.out.println("x + y = " + result);
result = x - y;
System.out.println("x - y = " + result);
result = x * y;
System.out.println("x * y = " + result);
result = y / x;
System.out.println("y / x = " + result);
result = x % 3;
System.out.println("x % 3 = " + result);
}
}

(b) public class testOperator2 {


public static void main(String[] args) {
int x =0 ,y = 10, z=0;
x = ++y;
System.out.println("x = " + x);
System.out.println("y = " + y);
z = x++;
System.out.println("x = " + x);
System.out.println("z = " + z);
}
}

2. Write a Java program to print the result of the following operations.

(a) ((32 ∗ 4) − (5 + 2 ∗ 3))/(9 − 4)


(b) ((6 + 23 ) ∗ (15 − 6))%(7 + 5)
(c) (8 ∗ (4 + 3) − (2 ∗ 5))/(10 − 32 )
(d) ((12 + 6 ∗ 2) − (42 − 7))/(5 + 2)
(e) ((32 ∗ 5) + (7 − 4 ∗ 2))/(6 − 2)
3. Write a java program to get a Fibonacci series by taking next number as the sum of the
previous two numbers.
For example: 0,1,1,2,3,5,8,13,21,34,55, etc.

4. i) Create a Java program that declares two integer variables a and b and initializes them
with values.
ii) Use compound operators to perform the following operations and update the values
of a and b:
(a) Add 5 to a.
(b) Subtract 3 from b.
(c) Multiply a by 2.
(d) Divide b by 4.
(e) Calculate the remainder of a when divided by 7.
iii) Print the values of a and b before and after each operation. Use separate print state-
ments to make the output clear.
iv) Ensure that the program demonstrates the use of compound operators for each oper-
ation mentioned above.

5. Write a Java program to convert a temperature given in Celsius(C) to Fahrenheit(F):

F = (C × 1.8) + 32

6. Write a Java program to find the area of the circle when the value for radius is given:

Area = π × r2

7. The diameter of the Sun is approximately 865,000 miles. The diameter of the Earth is
approximately 7,600 miles. Write a Jave program to calculate the followings:

(a) The volume of the Earth in cubic miles


(b) The volume of the Sun in cubic miles
(c) The ratio of the volume of the Sun to the volume of the Earth

(Hint: Volume of a sphere is given by 34 πr3 where r is the radius.)

****************************************

You might also like