[go: up one dir, main page]

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

lab2

Uploaded by

vaggaanand124
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views2 pages

lab2

Uploaded by

vaggaanand124
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

// program to print Fibonacci series from given range

package com.ajp;

import java.util.Scanner;

public class Fibonacci {

static void fib(int range) {


int first=0 ,second=1;
for(int i=1; i<=range; i++)
{
System.out.print(first+" ");
int third = first + second;
first=second;
second=third;
}

public static void main(String[] args) {


// TODO Auto-generated method stub
Scanner sc=new Scanner(System.in);
fib(sc.nextInt());
}

// program to check a num is strong num or not

package com.ajp;
import java.util.Scanner;

public class StrongNumber {

public static int factorial(int num) {


int fact = 1;
for (int i = 1; i <= num; i++) {
fact *= i;
}
return fact;
}
public static boolean isStrongNum(int number) {
int orgNum,digit,sum = 0;
orgNum = number;
while (number > 0) {
digit = number % 10;
sum += factorial(digit);
number /= 10;
}

return sum==orgNum;
}

public static void main(String[] args) {


Scanner sc= new Scanner(System.in);
int num = sc.nextInt();
if (isStrongNum(num)) {
System.out.println(num + " is a strong number.");
} else {
System.out.println(num + " is not a strong number.");
}
}

You might also like