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

Java Programs Basics

The document contains four Java programs: one for checking if a number is a palindrome, another for calculating the factorial of a number, a third for determining if a number is prime, and a fourth for generating a Fibonacci series. Each program includes a main method demonstrating its functionality with specific examples. The code snippets illustrate basic programming concepts such as loops, conditionals, and arithmetic operations.

Uploaded by

abhipanda2004
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)
2 views2 pages

Java Programs Basics

The document contains four Java programs: one for checking if a number is a palindrome, another for calculating the factorial of a number, a third for determining if a number is prime, and a fourth for generating a Fibonacci series. Each program includes a main method demonstrating its functionality with specific examples. The code snippets illustrate basic programming concepts such as loops, conditionals, and arithmetic operations.

Uploaded by

abhipanda2004
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
You are on page 1/ 2

1.

Palindrome Check

public class PalindromeCheck {


public static void main(String[] args) {
int num = 121, reversed = 0, original = num;

while (num != 0) {
int digit = num % 10;
reversed = reversed * 10 + digit;
num /= 10;
}

if (original == reversed)
System.out.println(original + " is a palindrome.");
else
System.out.println(original + " is not a palindrome.");
}
}

2. Factorial of a Number

public class Factorial {


public static void main(String[] args) {
int num = 5;
long factorial = 1;

for (int i = 1; i <= num; ++i) {


factorial *= i;
}

System.out.println("Factorial of " + num + " = " + factorial);


}
}

3. Prime Number Check

public class PrimeCheck {


public static void main(String[] args) {
int num = 29, count = 0;

for (int i = 1; i <= num; ++i) {


if (num % i == 0)
count++;
}

if (count == 2)
System.out.println(num + " is a prime number.");
else
System.out.println(num + " is not a prime number.");
}
}

4. Fibonacci Series

public class FibonacciSeries {


public static void main(String[] args) {
int n = 10, first = 0, second = 1;

System.out.print("Fibonacci Series: " + first + ", " + second);

for (int i = 2; i < n; ++i) {


int next = first + second;
System.out.print(", " + next);
first = second;
second = next;
}
}
}

You might also like