The More I Help Others To Succeed, The More I Succeed

CS508 Assignment 3 Solution Spring 2021

Assignments 145
CS508 Assignment 3 Solution Spring 2021

CS508 Assignment 3 Solution Spring 2021

 Assignment No. 03
                        Semester: Spring 2021

CS508-Modern Programming Languages

VUSTD.COM

CS508 Assignment 3 Solution Spring 2021

Solution

Code

import java.util.Scanner;

public class Main

{

public static int isHappyNumber(int num)

{

int rem = 0, sum = 0;

//

while (num > 0)

{

rem = num % 10;

sum = sum + (rem * rem);

num = num / 10;

}

return sum;

}

public static void main(String[] args)

{

try {

Scanner scan = new Scanner(System.in);

String uid;

System.out.print(“please Enter your vu Id “);

uid = scan.nextline();

if (uid.length() <16 II uid.length() > 11)

{

System.out.prIntln(“Provided Student Id is Wrong”);

}

else

{

String id = uid.substring(2, 6);

System.out.println(id);

int count = Integer.parseInt(id.toString());

// Displays all happy numbers between 1 and N

System.out.println(“List of happy numbers between 1 and ” + id + ” as”);

for (int i = 1; i<=count count; i++)

{

int result = i;

  • Happy number reminder result 1 //unhappy number 4

while (result != 1 && result != 4)

{

result = isHappyNember(result);

}

if (result = 1)

{

System.out.print(I + ” “);

}

}

}

catch(NumberFormatException ex)

{

System.out.print(ex);

}

}

}

CS508 Assignment 3 Solution Spring 2021

CS508 Assignment 3 Solution Spring 2021

For More Assignments Details

Leave a Reply

Your email address will not be published.

Be silent and let your success shout