Uploading Instructions:: Tio - Run/#java-Jdk
Uploading Instructions:: Tio - Run/#java-Jdk
03
Total Marks: 20
Semester: Spring 2021 Due Date: 26 Jul 2021
CS508 – Modern Programming Languages
Please read the following instructions carefully before solving & submitting assignment:
Uploading Instructions:
o You can use simple Notepad or any other text editor (like Sublime Text, Atom, VS Code etc.) for coding.
o For compilation purpose, any online compiler can be consulted, like tio.run/#java-jdk
o Following files must be submitted in a single Zip or RAR file.
Java code file (file name should be your own VU Student Id, e.g., bs123456789.java)
A .gif file (e.g., bs123456789.gif) which should show only "execution" of your code (For
Recording .gif, a software named ScreenToGif is uploaded at VU-LMS; bit.ly/3edPzFX, or you can
use any other gif recording tool as well)
First record must be with your own VU Student Id in .gif file.
o After finalizing, put both files in a single folder, rename it to your own VU Student Id, compress it with Zip
or RAR format and submit at VU-LMS within due date.
o No assignment will be accepted through email.
Note: Do not put any query on MDB regarding this assignment, if you have any query then email at
[email protected]
GOOD LUCK
1
Assignment No. 03
Total Marks: 20
Semester: Spring 2021 Due Date: 26 Jul 2021
CS508 – Modern Programming Languages
Problem Statement:
A number (positive integer) is said to be a happy number if it yields 1 when it is replaced by the sum of the
square of its digits repeatedly. Or in simple words, the number for which the process of summing up of the
squares of its digits ends in 1 is a happy number. For example, 32 is a happy number as the process ends in
1, as shown below;
32 => 32 + 22 = 9 + 4 = 13
12 + 32 = 1 + 9 = 10
12 + 0 2 = 1 + 0 = 1
On the other hand, if number that does not end in 1 is called an unhappy or sad number. For example, 42 is
an unhappy number as the process does not end in 1, as shown below;
42 => 42 + 22 = 16 + 4 = 20
22 + 0 2 = 4 + 0 = 4
You are required to write a Java program which will print all happy numbers between 1 and first 4 digits
(after degree prefix) of your student id. If your student id is BS123456789 then print all happy numbers
between 1 and 1234.
2
Assignment No. 03
Total Marks: 20
Semester: Spring 2021 Due Date: 26 Jul 2021
CS508 – Modern Programming Languages
Note:
It is required to make sure that the program should not accept such student id which length is less
than 6 or greater than 12 characters. Furthermore, NumberFormatException must be implemented when
fetching first four digits (after degree prefix) from student id.
Sample Output:
See the gif file attached with this assignment file.
Compiler:
For compilation purpose, you can consult any online Java compiler, like tio.run/#java-jdk
Note:
DO REMEMBER that you must use your own VU Student ID as an input in this program.
Good Luck