Skip to content

Added Palindrome number program #8

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions palindrome.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import java.io.*;

public class palindrome {
public static void main(String[] args) throws IOException {
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
int num, reversedNum = 0, remainder;
System.out.println("Enter a number to check if it is palindrome or not");
num = Integer.parseInt(in.readLine());

// make a copy
int originalNum = num;

// reverse
while (num != 0) {
remainder = num % 10;
reversedNum = reversedNum * 10 + remainder;
num /= 10;
}

if (originalNum == reversedNum) {
System.out.println(originalNum + " is Palindrome.");
} else {
System.out.println(originalNum + " is not Palindrome.");

}

}
}
26 changes: 26 additions & 0 deletions prime.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import java.io.*;
public class prime {
public static void main(String[] args) throws IOException{
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
int number;
boolean flag = false;
System.out.println("Enter a number to check if it is prime or not");

number = Integer.parseInt(in.readLine());

for (int i = 2; i <= number / 2; ++i) {
// condition for nonprime number
if (number % i == 0) {
flag = true;
break;
}
}

if (!flag)
System.out.println(number + " is a prime number.");
else
System.out.println(number + " is not a prime number.");

}

}