0% found this document useful (0 votes)
15 views3 pages

Program 2

The document outlines a program with two Java applications that utilize command line arguments. The first program checks if a number is prime, while the second program verifies if a number is a palindrome. Both programs include source code demonstrating their functionality.

Uploaded by

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

Program 2

The document outlines a program with two Java applications that utilize command line arguments. The first program checks if a number is prime, while the second program verifies if a number is a palindrome. Both programs include source code demonstrating their functionality.

Uploaded by

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

PROGRAM: 2

OBJECTIVE: Creating simple java programs using command line arguments.


(a) WAP that takes input from user through command line argument and then prints whether a
number is prime or not.

(b) Write a program to enter number through command line and check whether it is palindrome or
not.

Source Code:
(a)
package labfile;
public class PRIME {
public static void main(String[] args) {
int n = [Link](args[0]); // get number from command line
boolean Prime = true;

if (n<= 1) {
Prime = false;
}

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


if (n % i == 0) {
Prime = false;
break;
}
}

if (Prime)
[Link](n + " Prime");
else
[Link](n + " Not Prime");
}
}

(b
)
package labfile;
public class Palindrome {
public static void main(String[] args) {
int num = [Link](args[0]);
int orig = num;
int rev = 0;
while (num > 0) {
int dig = num % 10;
rev = rev * 10 + dig;
num = num / 10;
}
if (orig == rev) {
[Link](orig + " is a Palindrome.");
} else {
[Link](orig + " is not a Palindrome.");
}
}
}
OUTPUT:

You might also like