Java Lab
Java Lab
ROLLNO : 12201221
COURSE : B.TECH (CSE)
YEAR : 3rd YEAR (5th SEMESTER)
SUBJECT : JAVA PROGRAMMING LAB
OUTPUT =>
PS E:\JAVA PROJECT> & 'C:\Program Files\Eclipse Adoptium\jdk-17.0.12.7-hotspot\bin\
java.exe' '-XX:+ShowCodeDetailsInExceptionMessages' '-cp' 'E:\JAVA PROJECT\bin' 'Calculator'
Enter the first number: 24
Enter the Second number: 45
Enter the choice (+ , - , * , /): +
24.0 + 45.0 = 69.0
Output =>
PS E:\JAVA PROJECT> & 'C:\Program Files\Eclipse Adoptium\jdk-17.0.12.7-hotspot\bin\
java.exe' '-XX:+ShowCodeDetailsInExceptionMessages' '-cp' 'E:\JAVA PROJECT\bin'
'Factorialrecursion'
Enter a number:
7
The factorial of 7 is : 5040
4) WAP to check wheather a given Number and String is palindrome or not
FOR NUMBER=>
import java.util.Scanner;
public class Palindrome {
public static void main(String[] arg) {
try (Scanner sc = new Scanner(System.in)) {
System.out.println("Enter a number: ");
int num = sc.nextInt();
int m = num;
int x = palindrome(num);
if (x == m) {
System.out.println("The number " + m + " is palindrome.");
} else {
System.out.println("The number " + m + " is not palindrome.");
}
}
}
public static int palindrome(int num) {
int reverse = 0;
while(num != 0){
int rem = num % 10;
reverse = reverse * 10 +rem;
num /= 10;
}
return reverse;
}
}
OUTPUT =>
PS E:\JAVA PROJECT> e:; cd 'e:\JAVA PROJECT'; & 'C:\Program Files\Eclipse Adoptium\jdk-
17.0.12.7-hotspot\bin\java.exe' '-XX:+ShowCodeDetailsInExceptionMessages' '-cp' 'E:\JAVA
PROJECT\bin' 'Palindrome'
Enter a number: 12221
The number 12221 is palindrome.
OUTPUT =>
PS E:\JAVA PROJECT> e:; cd 'e:\JAVA PROJECT'; & 'C:\Program Files\Eclipse Adoptium\jdk-
17.0.12.7-hotspot\bin\java.exe' '-XX:+ShowCodeDetailsInExceptionMessages' '-cp' 'E:\JAVA
PROJECT\bin' 'Palindromestring'
Enter the String you wnat to check: madam
madam is a palindrome string.