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

Java Number Programs

The document contains a collection of Java programs demonstrating various number-related algorithms, including Prime Numbers, Fibonacci sequence, Armstrong Numbers, and Palindrome checks. Each program is implemented as a separate class with a main method that executes the logic for its respective algorithm. Additional programs for other number types like Strong, Spy, and Automorphic are also mentioned but not detailed.

Uploaded by

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

Java Number Programs

The document contains a collection of Java programs demonstrating various number-related algorithms, including Prime Numbers, Fibonacci sequence, Armstrong Numbers, and Palindrome checks. Each program is implemented as a separate class with a main method that executes the logic for its respective algorithm. Additional programs for other number types like Strong, Spy, and Automorphic are also mentioned but not detailed.

Uploaded by

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

Java Number Programs Collection

Prime Numbers Program


public class PrimeNumbers {
public static void main(String[] args) {
for(int i = 2; i <= 100; i++) {
int count = 0;
for(int j = 1; j <= i; j++) {
if(i % j == 0) {
count++;
}
}
if(count == 2) {
[Link](i);
}
}
}
}

Fibonacci Program
public class Fibonacci {
public static void main(String[] args) {
int a = 0, b = 1, c;
[Link](a);
[Link](b);
for(int i = 1; i <= 10; i++) {
c = a + b;
[Link](c);
a = b;
b = c;
}
}
}

Armstrong Number Program


public class Armstrong {
public static void main(String[] args) {
int num = 153;
int temp = num;
int sum = 0;
int r;
while(num > 0) {
r = num % 10;
sum = sum + (r*r*r);
num = num / 10;
}
if(sum == temp)
[Link]("Armstrong Number");
else
[Link]("Not Armstrong");
}
}

Palindrome Program
public class Palindrome {
public static void main(String[] args) {
int num = 121;
int temp = num;
int rev = 0;
int r;
while(num > 0) {
r = num % 10;
rev = rev * 10 + r;
num = num / 10;
}
if(rev == temp)
[Link]("Palindrome");
else
[Link]("Not Palindrome");
}
}

(Other programs included similarly: Strong, Spy, Neon, Automorphic, Menu driven, Peterson, Duck, Sunny,

You might also like