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

Lab 5

The document contains four Java programs demonstrating different concepts. The first program showcases the use of wrapper classes with Integer, the second illustrates operations with BigInteger and BigDecimal, the third manipulates strings by reversing and replacing characters, and the fourth checks if a given string is a palindrome. Each program includes a main method that executes specific functionalities and prints the results.
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)
19 views2 pages

Lab 5

The document contains four Java programs demonstrating different concepts. The first program showcases the use of wrapper classes with Integer, the second illustrates operations with BigInteger and BigDecimal, the third manipulates strings by reversing and replacing characters, and the fourth checks if a given string is a palindrome. Each program includes a main method that executes specific functionalities and prints the results.
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

Q1:

public class WrapperExample {


public static void main(String[] args) {

Integer num = 42;

int primitiveNum = num;

System.out.println("Max Integer Value: " + Integer.MAX_VALUE);


System.out.println("Min Integer Value: " + Integer.MIN_VALUE);
}
}
Q2:
import java.math.BigInteger;
import java.math.BigDecimal;
import java.math.RoundingMode;

public class BigNumberExample {


public static void main(String[] args) {
BigInteger bigInt1 = new BigInteger("12345678901234567890");
BigInteger bigInt2 = new BigInteger("98765432109876543210");
BigInteger product = bigInt1.multiply(bigInt2);
System.out.println("BigInteger Product: " + product);

BigDecimal bigDec1 = new BigDecimal("22.0");


BigDecimal bigDec2 = new BigDecimal("7.0");
BigDecimal quotient = bigDec1.divide(bigDec2, 20,
RoundingMode.HALF_UP);
System.out.println("BigDecimal Quotient: " + quotient);
}
}
Q3:
public class StringManipulation {
public static void main(String[] args) {
String original = "Hello, World!";

StringBuilder reversed = new StringBuilder(original).reverse();


System.out.println("Reversed String: " + reversed);

String replaced = original.replace('l', 'X');


System.out.println("Replaced String: " + replaced);
}
}
Q4:
public class PalindromeChecker {
public static void main(String[] args) {
String input = "A man, a plan, a canal: Panama!";

String filtered = input.replaceAll("[^a-zA-Z0-9]", "").toLowerCase();


String reversed = new StringBuilder(filtered).reverse().toString();

boolean isPalindrome = filtered.equals(reversed);


System.out.println("Is Palindrome? " + isPalindrome);
}
}

You might also like