Please complete the following programs in Java
and confirm it with your respective faculty. You are free to use any IDE of your choice, writing the program's source code in a plain notepad program in also acceptable.
-
Program 1
Write a program in
Java
, to determine the sum of the following harmonic series for a given value ofn
;The value of
n
should be given interactively through the keyboard.Hint: Use the
Scanner
class from the packagejava.util.Scanner
.Note: In
Java
programming language, we assume the whole numbers as the typeint
by default and the rational numbers as the typedouble
by default.
-
Program 2
Write a program in
Java
, to read the price of an item in decimal form (like ₹45.95) and print the output in Rupees and Paise.45.95
45 Rupees and 95 Paise
-
Program 3
Write a program in
Java
, to covert the given temperature inFahrenheit
toCelsius
using the following conversion formula:and output the resulting value to the user.
97.4
36.333333
-
Program 4
Write a program in
Java
, to display the following to the console output window.1 2 2 3 3 3 4 4 4 4 5 5 5 5 5 6 6 6 6 6 6 7 7 7 7 7 7 7 8 8 8 8 8 8 8 8 9 9 9 9 9 9 9 9 9
-
Program 5
Write a program in
Java
, to display the day of the a date input by the user.Hint: You can study a sample formula for the given program here.
date: 15 month: 8 year: 2019
15th August 2019 was a Thursday!
The following programs have some form of compile-time errors
. Identify and remove the errors, so that the program runs successfully.
-
Program 1
public static void display() { int x = 123456; float f = 100.12; System.out.println("The float value = " + f); }
-
Program 2
public static void display() { int y; if (x > 10) { y = x; } System.out.println("The value of Y = " + y); }
-
Program 3
Modify the code in such a way, that the value of the variable
pi
is not modifiable (i.e it becomes a constant).public static void calculate() { float pi = 3.14f; System.out.println("The value of Pi = " + pi); }
-
Program 4
public static void convert() { int i = 1245; byte b = i; System.out.println("The value of the Byte variable b = " + b); }
-
Program 5
class ScopeDemo { public static void main(String[] args) { int m = 10; { int m = 20; } } }