fa
Feedback
Tech Jargon - Decoded

Tech Jargon - Decoded

رفتن به کانال در Telegram

Confused by tech terms? Don’t worry, we’ve got you 🤝 We make things simple, one concept at a time. Learn daily Easy & clear Turn Confusion into clarity. #tech #it #softwareengineer #cs #development

نمایش بیشتر
2 018
مشترکین
اطلاعاتی وجود ندارد24 ساعت
-77 روز
-4030 روز
آرشیو پست ها
💻 Create a Polynomial Class
import java.util.Scanner;

public class Polynomial {
    private int[] coefficients;

    public Polynomial(int degree) {
        coefficients = new int[degree + 1];
    }

    public void setCoefficient(int degree, int coefficient) {
        if (degree >= 0 && degree < coefficients.length) {
            coefficients[degree] = coefficient;
        }
    }

    public int getCoefficient(int degree) {
        if (degree >= 0 && degree < coefficients.length) {
            return coefficients[degree];
        } else {
            return 0;
        }
    }

    public int evaluate(int x) {
        int result = 0;
        for (int i = 0; i < coefficients.length; i++) {
            result += coefficients[i] * Math.pow(x, i);
        }
        return result;
    }

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        System.out.print("Enter the degree of the polynomial: ");
        int degree = scanner.nextInt();

        Polynomial polynomial = new Polynomial(degree);

        System.out.println("Enter the coefficients for each degree (starting from degree 0):");
        for (int i = 0; i <= degree; i++) {
            System.out.print("Coefficient for degree " + i + ": ");
            int coefficient = scanner.nextInt();
            polynomial.setCoefficient(i, coefficient);
        }

        System.out.print("Enter the value of x to evaluate the polynomial: ");
        int x = scanner.nextInt();

        int result = polynomial.evaluate(x);
        System.out.println("The result of the polynomial at x = " + x + " is: " + result);

        scanner.close();
    }
}
📤 Output:
Input: 2
Input: 1
Input: 2
Input: 3
Input: 4
Output: Enter the degree of the polynomial: Enter the coefficients for each degree (starting from degree 0):
Coefficient for degree 0: Coefficient for degree 1: Coefficient for degree 2: Enter the value of x to evaluate the polynomial: The result of the polynomial at x = 4 is: 57

💻 Create a Employee Class
import java.util.Scanner;

public class Employee {
    String employeeName;
    int employeeId;
    double employeeSalary;

    public Employee(String name, int id, double salary) {
        employeeName = name;
        employeeId = id;
        employeeSalary = salary;
    }

    public void displayEmployeeDetails() {
        System.out.println("Employee Name: " + employeeName);
        System.out.println("Employee ID: " + employeeId);
        System.out.println("Employee Salary: " + employeeSalary);
    }

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        System.out.print("Enter employee name: ");
        String name = scanner.nextLine();

        System.out.print("Enter employee ID: ");
        int id = scanner.nextInt();
        scanner.nextLine(); // Consume newline

        System.out.print("Enter employee salary: ");
        double salary = scanner.nextDouble();

        Employee emp = new Employee(name, id, salary);
        emp.displayEmployeeDetails();

        scanner.close();
    }
}
📤 Output:
Input: John Doe
Input: 12345
Input: 60000.0
Output: Employee Name: John Doe
Output: Employee ID: 12345
Output: Employee Salary: 60000.0

💻 Create a Book Class
import java.util.Scanner;

public class Book {

    String title;
    String author;
    int pages;

    public Book(String title, String author, int pages) {
        this.title = title;
        this.author = author;
        this.pages = pages;
    }

    public void displayBookDetails() {
        System.out.println("Title: " + title);
        System.out.println("Author: " + author);
        System.out.println("Number of Pages: " + pages);
    }

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        System.out.print("Enter the title of the book: ");
        String title = scanner.nextLine();

        System.out.print("Enter the author of the book: ");
        String author = scanner.nextLine();

        System.out.print("Enter the number of pages in the book: ");
        int pages = scanner.nextInt();
        scanner.nextLine(); // Consume newline character

        Book myBook = new Book(title, author, pages);

        System.out.println("nBook Details:");
        myBook.displayBookDetails();

        scanner.close();
    }
}
📤 Output:
Input: The Lord of the Rings
Input: J.R.R. Tolkien
Input: 1178
Output: Enter the title of the book: Enter the author of the book: Enter the number of pages in the book:
Book Details:
Title: The Lord of the Rings
Author: J.R.R. Tolkien
Number of Pages: 1178

💻 Create a Shopping Cart Class
import java.util.ArrayList;
import java.util.Scanner;

public class ShoppingCart {

    private ArrayList<String> items;

    public ShoppingCart() {
        items = new ArrayList<>();
    }

    public void addItem(String item) {
        items.add(item);
        System.out.println(item + " added to the cart.");
    }

    public void removeItem(String item) {
        if (items.contains(item)) {
            items.remove(item);
            System.out.println(item + " removed from the cart.");
        } else {
            System.out.println(item + " is not in the cart.");
        }
    }

    public void displayCart() {
        if (items.isEmpty()) {
            System.out.println("The cart is empty.");
        } else {
            System.out.println("Items in the cart:");
            for (int i = 0; i < items.size(); i++) {
                System.out.println((i + 1) + ". " + items.get(i));
            }
        }
    }

    public static void main(String[] args) {
        ShoppingCart myCart = new ShoppingCart();
        Scanner scanner = new Scanner(System.in);

        while (true) {
            System.out.println("nOptions:");
            System.out.println("1. Add item");
            System.out.println("2. Remove item");
            System.out.println("3. View cart");
            System.out.println("4. Exit");
            System.out.print("Enter your choice: ");

            int choice = scanner.nextInt();
            scanner.nextLine(); // Consume newline

            switch (choice) {
                case 1:
                    System.out.print("Enter item to add: ");
                    String itemToAdd = scanner.nextLine();
                    myCart.addItem(itemToAdd);
                    break;
                case 2:
                    System.out.print("Enter item to remove: ");
                    String itemToRemove = scanner.nextLine();
                    myCart.removeItem(itemToRemove);
                    break;
                case 3:
                    myCart.displayCart();
                    break;
                case 4:
                    System.out.println("Exiting...");
                    scanner.close();
                    return;
                default:
                    System.out.println("Invalid choice. Please try again.");
            }
        }
    }
}
📤 Output:
Options:
1. Add item
2. Remove item
3. View cart
4. Exit
Enter your choice: Input: 1
Enter item to add: Input: Milk
Milk added to the cart.

Options:
1. Add item
2. Remove item
3. View cart
4. Exit
Enter your choice: Input: 1
Enter item to add: Input: Bread
Bread added to the cart.

Options:
1. Add item
2. Remove item
3. View cart
4. Exit
Enter your choice: Input: 3
Items in the cart:
1. Milk
2. Bread

Options:
1. Add item
2. Remove item
3. View cart
4. Exit
Enter your choice: Input: 2
Enter item to remove: Input: Milk
Milk removed from the cart.

Options:
1. Add item
2. Remove item
3. View cart
4. Exit
Enter your choice: Input: 3
Items in the cart:
1. Bread

Options:
1. Add item
2. Remove item
3. View cart
4. Exit
Enter your choice: Input: 2
Enter item to remove: Input: Eggs
Eggs is not in the cart.

Options:
1. Add item
2. Remove item
3. View cart
4. Exit
Enter your choice: Input: 4
Exiting...

💻 Create a Line Class
import java.util.Scanner;

public class LineClass {
    private double x1, y1, x2, y2;

    public LineClass(double x1, double y1, double x2, double y2) {
        this.x1 = x1;
        this.y1 = y1;
        this.x2 = x2;
        this.y2 = y2;
    }

    public double getLength() {
        return Math.sqrt(Math.pow(x2 - x1, 2) + Math.pow(y2 - y1, 2));
    }

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        System.out.print("Enter x1 coordinate: ");
        double x1 = scanner.nextDouble();

        System.out.print("Enter y1 coordinate: ");
        double y1 = scanner.nextDouble();

        System.out.print("Enter x2 coordinate: ");
        double x2 = scanner.nextDouble();

        System.out.print("Enter y2 coordinate: ");
        double y2 = scanner.nextDouble();

        LineClass line = new LineClass(x1, y1, x2, y2);

        System.out.println("Length of the line: " + line.getLength());

        scanner.close();
    }
}
📤 Output:
Input: 0
Input: 0
Input: 3
Input: 4
Output: Length of the line: 5.0

💻 Create a Point Class
import java.util.Scanner;

public class PointClass {

    private int xCoordinate;
    private int yCoordinate;

    public PointClass(int x, int y) {
        this.xCoordinate = x;
        this.yCoordinate = y;
    }

    public int getXCoordinate() {
        return xCoordinate;
    }

    public int getYCoordinate() {
        return yCoordinate;
    }

    public void setXCoordinate(int x) {
        this.xCoordinate = x;
    }

    public void setYCoordinate(int y) {
        this.yCoordinate = y;
    }

    public void displayPoint() {
        System.out.println("X Coordinate: " + xCoordinate);
        System.out.println("Y Coordinate: " + yCoordinate);
    }

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        System.out.print("Enter X coordinate: ");
        int x = scanner.nextInt();

        System.out.print("Enter Y coordinate: ");
        int y = scanner.nextInt();

        PointClass myPoint = new PointClass(x, y);

        System.out.println("nPoint Details:");
        myPoint.displayPoint();

        scanner.close();
    }
}
📤 Output:
Input: 5
Input: 10
Output:
Enter X coordinate: Enter Y coordinate:
Point Details:
X Coordinate: 5
Y Coordinate: 10

💻 Create a Fraction Class
import java.util.Scanner;

public class FractionClass {

    private int numerator;
    private int denominator;

    public FractionClass(int numerator, int denominator) {
        this.numerator = numerator;
        if (denominator == 0) {
            System.out.println("Denominator cannot be zero. Setting it to 1.");
            this.denominator = 1;
        } else {
            this.denominator = denominator;
        }
    }

    public int getNumerator() {
        return numerator;
    }

    public int getDenominator() {
        return denominator;
    }

    public void setNumerator(int numerator) {
        this.numerator = numerator;
    }

    public void setDenominator(int denominator) {
        if (denominator == 0) {
            System.out.println("Denominator cannot be zero. Not changing it.");
        } else {
            this.denominator = denominator;
        }
    }

    public String toString() {
        return numerator + "/" + denominator;
    }

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        System.out.print("Enter the numerator: ");
        int num = scanner.nextInt();

        System.out.print("Enter the denominator: ");
        int den = scanner.nextInt();

        FractionClass myFraction = new FractionClass(num, den);

        System.out.println("The fraction is: " + myFraction.toString());

        System.out.print("Enter a new numerator: ");
        int newNum = scanner.nextInt();
        myFraction.setNumerator(newNum);

        System.out.println("The updated fraction is: " + myFraction.toString());

        scanner.close();
    }
}
📤 Output:
Input: 5
Input: 2
Output: The fraction is: 5/2
Input: 7
Output: The updated fraction is: 7/2

💻 Create a Date Class
import java.util.Scanner;

public class DateClass {

    private int day;
    private int month;
    private int year;

    public DateClass(int day, int month, int year) {
        this.day = day;
        this.month = month;
        this.year = year;
    }

    public void displayDate() {
        System.out.println(day + "/" + month + "/" + year);
    }

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        System.out.print("Enter day: ");
        int day = scanner.nextInt();

        System.out.print("Enter month: ");
        int month = scanner.nextInt();

        System.out.print("Enter year: ");
        int year = scanner.nextInt();

        DateClass myDate = new DateClass(day, month, year);

        System.out.print("The date you entered is: ");
        myDate.displayDate();

        scanner.close();
    }
}
📤 Output:
Input: 15
Input: 8
Input: 2023
Output: Enter day: Enter month: Enter year: The date you entered is: 15/8/2023

💻 Create a Time Class
import java.util.Scanner;

public class TimeClass {

    private int hours;
    private int minutes;
    private int seconds;

    public TimeClass(int hours, int minutes, int seconds) {
        this.hours = hours;
        this.minutes = minutes;
        this.seconds = seconds;
    }

    public int getHours() {
        return hours;
    }

    public void setHours(int hours) {
        this.hours = hours;
    }

    public int getMinutes() {
        return minutes;
    }

    public void setMinutes(int minutes) {
        this.minutes = minutes;
    }

    public int getSeconds() {
        return seconds;
    }

    public void setSeconds(int seconds) {
        this.seconds = seconds;
    }

    public void displayTime() {
        System.out.println("Time: " + hours + ":" + minutes + ":" + seconds);
    }

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        System.out.print("Enter hours: ");
        int hours = scanner.nextInt();

        System.out.print("Enter minutes: ");
        int minutes = scanner.nextInt();

        System.out.print("Enter seconds: ");
        int seconds = scanner.nextInt();

        TimeClass myTime = new TimeClass(hours, minutes, seconds);
        myTime.displayTime();

        scanner.close();
    }
}
📤 Output:
Input: 10
Input: 30
Input: 45
Output: Time: 10:30:45

💻 Create a Complex Number Class
import java.util.Scanner;

public class ComplexNumber {
    private double real;
    private double imaginary;

    public ComplexNumber(double real, double imaginary) {
        this.real = real;
        this.imaginary = imaginary;
    }

    public double getReal() {
        return real;
    }

    public double getImaginary() {
        return imaginary;
    }

    public ComplexNumber add(ComplexNumber other) {
        double newReal = this.real + other.real;
        double newImaginary = this.imaginary + other.imaginary;
        return new ComplexNumber(newReal, newImaginary);
    }

    public String toString() {
        return real + " + " + imaginary + "i";
    }

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        System.out.print("Enter real part of first complex number: ");
        double real1 = scanner.nextDouble();
        System.out.print("Enter imaginary part of first complex number: ");
        double imaginary1 = scanner.nextDouble();

        ComplexNumber complex1 = new ComplexNumber(real1, imaginary1);

        System.out.print("Enter real part of second complex number: ");
        double real2 = scanner.nextDouble();
        System.out.print("Enter imaginary part of second complex number: ");
        double imaginary2 = scanner.nextDouble();

        ComplexNumber complex2 = new ComplexNumber(real2, imaginary2);

        ComplexNumber sum = complex1.add(complex2);

        System.out.println("First Complex Number: " + complex1);
        System.out.println("Second Complex Number: " + complex2);
        System.out.println("Sum: " + sum);

        scanner.close();
    }
}
📤 Output:
Input: 1.0
Input: 2.0
Input: 3.0
Input: 4.0
Output: Enter real part of first complex number: Enter imaginary part of first complex number: Enter real part of second complex number: Enter imaginary part of second complex number: First Complex Number: 1.0 + 2.0i
Second Complex Number: 3.0 + 4.0i
Sum: 4.0 + 6.0i

💻 Create a Circle Class
import java.util.Scanner;

public class CircleClass {

    private double radius;

    public CircleClass(double radius) {
        this.radius = radius;
    }

    public double calculateArea() {
        return Math.PI * radius * radius;
    }

    public double calculateCircumference() {
        return 2 * Math.PI * radius;
    }

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        System.out.print("Enter the radius of the circle: ");
        double radius = scanner.nextDouble();

        CircleClass myCircle = new CircleClass(radius);

        double area = myCircle.calculateArea();
        double circumference = myCircle.calculateCircumference();

        System.out.println("Area of the circle: " + area);
        System.out.println("Circumference of the circle: " + circumference);

        scanner.close();
    }
}
📤 Output:
Input: 5
Output: Enter the radius of the circle: Area of the circle: 78.53981633974483
Circumference of the circle: 31.41592653589793

💻 Create a Car Class
import java.util.Scanner;

public class CarDetails {
    String carModel;
    String carColor;
    int modelYear;

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        CarDetails myCar = new CarDetails();

        System.out.print("Enter car model: ");
        myCar.carModel = scanner.nextLine();

        System.out.print("Enter car color: ");
        myCar.carColor = scanner.nextLine();

        System.out.print("Enter model year: ");
        myCar.modelYear = scanner.nextInt();

        System.out.println("Car Details:");
        System.out.println("Model: " + myCar.carModel);
        System.out.println("Color: " + myCar.carColor);
        System.out.println("Year: " + myCar.modelYear);

        scanner.close();
    }
}
📤 Output:
Input: Toyota Camry
Input: Silver
Input: 2023
Output: Enter car model: Enter car color: Enter model year: Car Details:
Model: Toyota Camry
Color: Silver
Year: 2023

💻 Create a Student Class
import java.util.Scanner;

public class StudentClass {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        System.out.print("Enter student name: ");
        String studentName = scanner.nextLine();

        System.out.print("Enter student roll number: ");
        int studentRollNumber = scanner.nextInt();
        scanner.nextLine(); // Consume newline

        System.out.print("Enter student branch: ");
        String studentBranch = scanner.nextLine();

        System.out.println("nStudent Details:");
        System.out.println("Name: " + studentName);
        System.out.println("Roll Number: " + studentRollNumber);
        System.out.println("Branch: " + studentBranch);

        scanner.close();
    }
}
📤 Output:
Input: John Doe
Input: 123
Input: Computer Science
Output: Enter student name: Enter student roll number: Enter student branch:
Student Details:
Name: John Doe
Roll Number: 123
Branch: Computer Science

💻 Create a Rectangle Class
import java.util.Scanner;

public class RectangleClass {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        System.out.print("Enter the length of the rectangle: ");
        double length = scanner.nextDouble();

        System.out.print("Enter the breadth of the rectangle: ");
        double breadth = scanner.nextDouble();

        Rectangle rectangle = new Rectangle(length, breadth);

        System.out.println("Area of the rectangle: " + rectangle.calculateArea());
        System.out.println("Perimeter of the rectangle: " + rectangle.calculatePerimeter());

        scanner.close();
    }
}

class Rectangle {
    private double length;
    private double breadth;

    public Rectangle(double length, double breadth) {
        this.length = length;
        this.breadth = breadth;
    }

    public double calculateArea() {
        return length * breadth;
    }

    public double calculatePerimeter() {
        return 2 * (length + breadth);
    }
}
📤 Output:
Input: 5
Input: 10
Output: Enter the length of the rectangle: Enter the breadth of the rectangle: Area of the rectangle: 50.0
Output: Perimeter of the rectangle: 30.0

Choose an action: 1. Deposit 2. Withdraw 3. Check Balance 4. Exit Enter your choice: 4 Input: 4 Output: Exiting... ``` _(Part 2/2)_

💻 Create a Bank Account Class import java.util.Scanner; public class BankAccount { private String accountHolderName; private int accountNumber; private double balance; public BankAccount(String accountHolderName, int accountNumber, double initialBalance) { this.accountHolderName = accountHolderName; this.accountNumber = accountNumber; this.balance = initialBalance; } public void deposit(double amount) { if (amount > 0) { balance += amount; System.out.println("Deposit of ₹" + amount + " successful. New balance: ₹" + balance); } else { System.out.println("Invalid deposit amount."); } } public void withdraw(double amount) { if (amount > 0 && amount <= balance) { balance -= amount; System.out.println("Withdrawal of ₹" + amount + " successful. New balance: ₹" + balance); } else if (amount <= 0) { System.out.println("Invalid withdrawal amount."); } else { System.out.println("Insufficient balance."); } } public void checkBalance() { System.out.println("Account balance for " + accountHolderName + " (Account Number: " + accountNumber + "): ₹" + balance); } public static void main(String[] args) { Scanner scanner = new Scanner(System.in); System.out.print("Enter account holder name: "); String name = scanner.nextLine(); System.out.print("Enter account number: "); int number = scanner.nextInt(); System.out.print("Enter initial balance: ₹"); double initialBalance = scanner.nextDouble(); scanner.nextLine(); // Consume the newline character BankAccount account = new BankAccount(name, number, initialBalance); int choice; do { System.out.println("\nChoose an action:"); System.out.println("1. Deposit"); System.out.println("2. Withdraw"); System.out.println("3. Check Balance"); System.out.println("4. Exit"); System.out.print("Enter your choice: "); choice = scanner.nextInt(); scanner.nextLine(); // Consume the newline character switch (choice) { case 1: System.out.print("Enter deposit amount: ₹"); double depositAmount = scanner.nextDouble(); account.deposit(depositAmount); scanner.nextLine(); // Consume the newline character break; case 2: System.out.print("Enter withdrawal amount: ₹"); double withdrawalAmount = scanner.nextDouble(); account.withdraw(withdrawalAmount); scanner.nextLine(); // Consume the newline character break; case 3: account.checkBalance(); break; case 4: System.out.println("Exiting..."); break; default: System.out.println("Invalid choice. Please try again."); } } while (choice != 4); scanner.close(); } } 📤 Output: ``` Enter account holder name: John Doe Enter account number: 12345 Enter initial balance: ₹1000 Input: 1000 Choose an action: 1. Deposit 2. Withdraw 3. Check Balance 4. Exit Enter your choice: 1 Input: 1 Enter deposit amount: ₹500 Input: 500 Output: Deposit of ₹500.0 successful. New balance: ₹1500.0 Choose an action: 1. Deposit 2. Withdraw 3. Check Balance 4. Exit Enter your choice: 2 Input: 2 Enter withdrawal amount: ₹200 Input: 200 Output: Withdrawal of ₹200.0 successful. New balance: ₹1300.0 Choose an action: 1. Deposit 2. Withdraw 3. Check Balance 4. Exit Enter your choice: 3 Input: 3 Output: Account balance for John Doe (Account Number: 12345): ₹1300.0 _(Part 1/2)_

💻 Create a Simple Class (Person with name, age)
import java.util.Scanner;

public class Person {
    String name;
    int age;

    public Person(String name, int age) {
        this.name = name;
        this.age = age;
    }

    public void displayDetails() {
        System.out.println("Name: " + this.name);
        System.out.println("Age: " + this.age);
    }

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        System.out.print("Enter the name: ");
        String name = scanner.nextLine();

        System.out.print("Enter the age: ");
        int age = scanner.nextInt();

        Person person = new Person(name, age);
        person.displayDetails();

        scanner.close();
    }
}
📤 Output:
Input: John Doe
Input: 30
Output: Enter the name: Enter the age: Name: John Doe
Output: Age: 30

OOP - Classes & Objects

💻 String Builder Operations
import java.util.Scanner;

public class StringBuilderOperations {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        System.out.println("Enter a string:");
        String inputString = scanner.nextLine();

        StringBuilder stringBuilder = new StringBuilder(inputString);

        System.out.println("Original string: " + stringBuilder);

        System.out.println("Enter text to append:");
        String textToAppend = scanner.nextLine();
        stringBuilder.append(textToAppend);
        System.out.println("After appending: " + stringBuilder);

        System.out.println("Enter the index to insert at:");
        int insertIndex = scanner.nextInt();
        scanner.nextLine(); // Consume newline
        System.out.println("Enter text to insert:");
        String textToInsert = scanner.nextLine();
        stringBuilder.insert(insertIndex, textToInsert);
        System.out.println("After inserting: " + stringBuilder);

        System.out.println("Enter start index to delete from:");
        int startIndex = scanner.nextInt();
        System.out.println("Enter end index to delete to (exclusive):");
        int endIndex = scanner.nextInt();
        stringBuilder.delete(startIndex, endIndex);
        System.out.println("After deleting: " + stringBuilder);

        System.out.println("Reversed string: " + stringBuilder.reverse());

        scanner.close();
    }
}
📤 Output:
Enter a string:
Input: Hello
Output: Original string: Hello
Enter text to append:
Input: World
Output: After appending: HelloWorld
Enter the index to insert at:
Input: 5
Output: Enter text to insert:
Input: there
Output: After inserting: HellothereWorld
Enter start index to delete from:
Input: 5
Output: Enter end index to delete to (exclusive):
Input: 10
Output: After deleting: HelloWorld
Output: Reversed string: dlroWolleH

💻 String Tokenization
import java.util.Scanner;
import java.util.StringTokenizer;

public class StringTokenization {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        System.out.println("Enter a string to tokenize: ");
        String inputString = scanner.nextLine();

        System.out.println("Enter the delimiter (e.g., comma, space): ");
        String delimiter = scanner.nextLine();

        StringTokenizer tokenizer = new StringTokenizer(inputString, delimiter);

        System.out.println("Tokens are:");
        while (tokenizer.hasMoreTokens()) {
            String token = tokenizer.nextToken();
            System.out.println(token);
        }

        scanner.close();
    }
}
📤 Output:
Input: This is, a sample string.
Input: ,
Output: Enter a string to tokenize:
Enter the delimiter (e.g., comma, space):
Tokens are:
This is
 a sample string.
Input: Hello World!
Input:
Output: Enter a string to tokenize:
Enter the delimiter (e.g., comma, space):
Tokens are:
H
e
l
l
o

W
o
r
l
d
!
Input: apple banana orange
Input:
Output: Enter a string to tokenize:
Enter the delimiter (e.g., comma, space):
Tokens are:
apple
banana
orange
Input: one two three four
Input:
Output: Enter a string to tokenize:
Enter the delimiter (e.g., comma, space):
Tokens are:
one two three four
Input: a,b,c,d,e
Input: ,
Output: Enter a string to tokenize:
Enter the delimiter (e.g., comma, space):
Tokens are:
a
b
c
d
e
Input:  123 456 789
Input:
Output: Enter a string to tokenize:
Enter the delimiter (e.g., comma, space):
Tokens are:
123 456 789
Input: test-string
Input: -
Output: Enter a string to tokenize:
Enter the delimiter (e.g., comma, space):
Tokens are:
test
string
Input: example string
Input: x
Output: Enter a string to tokenize:
Enter the delimiter (e.g., comma, space):
Tokens are:
e
ample string