www.vustudents.ning.com

We non-commercial site working hard since 2009 to facilitate learning Read More. We can't keep up without your support. Donate.

# CS508 Assignment no 3 Solution Spring 2021| Must Watch

Views: 498

### Replies to This Discussion

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;
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);
}
}
}

kindly check the errors

Error Free Code :)

cs508.....rtf

1

2

3

4

5

## Latest Activity

19 minutes ago
27 minutes ago
سعيد احمد liked ASIM!!'s discussion Faisla
2 hours ago

3 hours ago
Naseer ullah posted discussions
4 hours ago
5 hours ago
Naseer ullah added a discussion to the group ECO401 Economics

### Eco401 Midterm 2021 GrandQuiz (100% Correct Solution)

6 hours ago
Naseer ullah joined + M.Tariq Malik's group

6 hours ago