ru
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 день
Архив постов
💻 Method to Check Strong Number
import java.util.Scanner;

public class StrongNumberChecker {

    public static int factorial(int number) {
        int fact = 1;
        for (int i = 1; i <= number; i++) {
            fact = fact * i;
        }
        return fact;
    }

    public static boolean isStrongNumber(int number) {
        int originalNumber = number;
        int sum = 0;
        while (number != 0) {
            int digit = number % 10;
            sum = sum + factorial(digit);
            number = number / 10;
        }
        return sum == originalNumber;
    }

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        System.out.print("Enter a number: ");
        int number = scanner.nextInt();

        if (isStrongNumber(number)) {
            System.out.println(number + " is a strong number.");
        } else {
            System.out.println(number + " is not a strong number.");
        }

        scanner.close();
    }
}
📤 Output:
Input: 145
Output: 145 is a strong number.

Input: 123
Output: 123 is not a strong number.

Input: 40585
Output: 40585 is not a strong number.

Input: 0
Output: 0 is not a strong number.

Input: 1
Output: 1 is a strong number.

Input: 2
Output: 2 is a strong number.

💻 Method to Check Perfect Number
import java.util.Scanner;

public class PerfectNumberChecker {

    public static boolean isPerfectNumber(int number) {
        if (number <= 1) {
            return false;
        }

        int sumOfDivisors = 1;
        for (int i = 2; i * i <= number; i++) {
            if (number % i == 0) {
                sumOfDivisors += i;
                if (i * i != number) {
                    sumOfDivisors += number / i;
                }
            }
        }

        return sumOfDivisors == number;
    }

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        System.out.print("Enter a number: ");
        int num = scanner.nextInt();

        if (isPerfectNumber(num)) {
            System.out.println(num + " is a perfect number.");
        } else {
            System.out.println(num + " is not a perfect number.");
        }

        scanner.close();
    }
}
📤 Output:
Input: 6
Output: 6 is a perfect number.

Input: 28
Output: 28 is a perfect number.

Input: 12
Output: 12 is not a perfect number.

Input: 496
Output: 496 is a perfect number.

Input: 8128
Output: 8128 is a perfect number.

Input: 33550336
Output: 33550336 is a perfect number.

💻 Method to Convert Binary to Decimal
import java.util.Scanner;

public class BinaryToDecimalConverter {

    public static int binaryToDecimal(String binaryString) {
        int decimalValue = 0;
        int power = 0;

        for (int i = binaryString.length() - 1; i >= 0; i--) {
            if (binaryString.charAt(i) == '1') {
                decimalValue += Math.pow(2, power);
            }
            power++;
        }
        return decimalValue;
    }

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

        System.out.print("Enter a binary number: ");
        String binaryInput = scanner.nextLine();

        int decimalOutput = binaryToDecimal(binaryInput);
        System.out.println("Decimal equivalent: " + decimalOutput);

        scanner.close();
    }
}
📤 Output:
Input: 101101
Output: Decimal equivalent: 45

Input: 1111
Output: Decimal equivalent: 15

Input: 10000000
Output: Decimal equivalent: 128

Input: 0
Output: Decimal equivalent: 0

Input: 1
Output: Decimal equivalent: 1

💻 Method to Convert Decimal to Binary
import java.util.Scanner;

public class DecimalToBinaryConverter {

    public static String decimalToBinary(int decimalNumber) {
        if (decimalNumber == 0) {
            return "0";
        }

        StringBuilder binary = new StringBuilder();
        while (decimalNumber > 0) {
            int remainder = decimalNumber % 2;
            binary.insert(0, remainder); // Add remainder to the beginning
            decimalNumber = decimalNumber / 2;
        }
        return binary.toString();
    }

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        System.out.print("Enter a decimal number: ");
        int decimalNumber = scanner.nextInt();
        scanner.close();

        String binaryNumber = decimalToBinary(decimalNumber);
        System.out.println("Binary equivalent: " + binaryNumber);
    }
}
📤 Output:
Input: 10
Output: Enter a decimal number: Binary equivalent: 1010

Input: 0
Output: Enter a decimal number: Binary equivalent: 0

Input: 42
Output: Enter a decimal number: Binary equivalent: 101010

Input: 12345
Output: Enter a decimal number: Binary equivalent: 11000000111001

💻 Method to Calculate Sum of Digits
import java.util.Scanner;

public class SumOfDigits {

    public static int calculateSumOfDigits(int number) {
        int sum = 0;
        while (number > 0) {
            int digit = number % 10;
            sum = sum + digit;
            number = number / 10;
        }
        return sum;
    }

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        System.out.print("Enter a number: ");
        int number = scanner.nextInt();

        int sumOfDigits = calculateSumOfDigits(number);
        System.out.println("Sum of digits: " + sumOfDigits);

        scanner.close();
    }
}
📤 Output:
Input: 12345
Output: Enter a number: Sum of digits: 15

Input: 987
Output: Enter a number: Sum of digits: 24

Input: 0
Output: Enter a number: Sum of digits: 0

💻 Method to Reverse a Number
import java.util.Scanner;

public class ReverseNumberMethod {

    public static int reverseNumber(int number) {
        int reversedNumber = 0;
        while (number != 0) {
            int remainder = number % 10;
            reversedNumber = reversedNumber * 10 + remainder;
            number = number / 10;
        }
        return reversedNumber;
    }

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        System.out.print("Enter a number: ");
        int originalNumber = scanner.nextInt();

        int reversedNumber = reverseNumber(originalNumber);

        System.out.println("Reversed number: " + reversedNumber);
        scanner.close();
    }
}
📤 Output:
Input: 12345
Output: Enter a number: Reversed number: 54321

Input: 1000
Output: Enter a number: Reversed number: 1

Input: 0
Output: Enter a number: Reversed number: 0

💻 Method to Print Fibonacci Series
import java.util.Scanner;

public class FibonacciSeriesMethod {

    public static void printFibonacciSeries(int limit) {
        int firstNum = 0;
        int secondNum = 1;

        System.out.print("Fibonacci Series up to " + limit + ": ");

        while (firstNum <= limit) {
            System.out.print(firstNum + " ");

            int nextNum = firstNum + secondNum;
            firstNum = secondNum;
            secondNum = nextNum;
        }
        System.out.println();
    }

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

        System.out.print("Enter the limit for the Fibonacci series: ");
        int limit = scanner.nextInt();

        printFibonacciSeries(limit);

        scanner.close();
    }
}
📤 Output:
Input: 10
Output: Enter the limit for the Fibonacci series: Fibonacci Series up to 10: 0 1 1 2 3 5 8
Input: 20
Output: Enter the limit for the Fibonacci series: Fibonacci Series up to 20: 0 1 1 2 3 5 8 13
Input: 1
Output: Enter the limit for the Fibonacci series: Fibonacci Series up to 1: 0 1 1

💻 Method to Calculate LCM
import java.util.Scanner;

public class LcmCalculator {

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

        System.out.print("Enter the first number: ");
        int number1 = scanner.nextInt();

        System.out.print("Enter the second number: ");
        int number2 = scanner.nextInt();

        int lcm = calculateLcm(number1, number2);

        System.out.println("LCM of " + number1 + " and " + number2 + " is: " + lcm);

        scanner.close();
    }

    public static int calculateLcm(int num1, int num2) {
        int gcd = calculateGcd(num1, num2);
        return (num1 * num2) / gcd;
    }

    public static int calculateGcd(int num1, int num2) {
        while (num2 != 0) {
            int temp = num2;
            num2 = num1 % num2;
            num1 = temp;
        }
        return num1;
    }
}
📤 Output:
Input: 12
Input: 18
Output: LCM of 12 and 18 is: 36

💻 Method to Calculate GCD/HCF (Euclidean Algorithm)
import java.util.Scanner;

public class GCDCalculator {

    public static int calculateGCD(int number1, int number2) {
        while (number2 != 0) {
            int temp = number2;
            number2 = number1 % number2;
            number1 = temp;
        }
        return number1;
    }

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

        System.out.print("Enter the first number: ");
        int firstNumber = scanner.nextInt();

        System.out.print("Enter the second number: ");
        int secondNumber = scanner.nextInt();

        int gcd = calculateGCD(firstNumber, secondNumber);
        System.out.println("GCD of " + firstNumber + " and " + secondNumber + " is: " + gcd);

        scanner.close();
    }
}
📤 Output:
Input: 48
Input: 18
Output: GCD of 48 and 18 is: 6

💻 Method to Check Armstrong Number
import java.util.Scanner;

public class ArmstrongNumberChecker {

    public static boolean isArmstrong(int number) {
        int originalNumber = number;
        int numberOfDigits = 0;
        int sum = 0;
        int tempNumber = number;

        // Count the number of digits
        while (tempNumber != 0) {
            tempNumber /= 10;
            numberOfDigits++;
        }

        // Calculate the sum of digits raised to the power of numberOfDigits
        tempNumber = number;
        while (tempNumber != 0) {
            int remainder = tempNumber % 10;
            sum += Math.pow(remainder, numberOfDigits);
            tempNumber /= 10;
        }

        // Check if the sum is equal to the original number
        return sum == originalNumber;
    }

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        System.out.print("Enter a number: ");
        int number = scanner.nextInt();

        if (isArmstrong(number)) {
            System.out.println(number + " is an Armstrong number.");
        } else {
            System.out.println(number + " is not an Armstrong number.");
        }

        scanner.close();
    }
}
📤 Output:
Input: 153
Output: 153 is an Armstrong number.

Input: 120
Output: 120 is not an Armstrong number.

Input: 370
Output: 370 is an Armstrong number.

Input: 371
Output: 371 is an Armstrong number.

Input: 407
Output: 407 is an Armstrong number.

Input: 1634
Output: 1634 is an Armstrong number.

Input: 8208
Output: 8208 is an Armstrong number.

Input: 54748
Output: 54748 is an Armstrong number.

Input: 9474
Output: 9474 is an Armstrong number.

Input: 5
Output: 5 is an Armstrong number.

💻 Method to Check Palindrome
import java.util.Scanner;

public class PalindromeChecker {

    public static boolean isPalindrome(String str) {
        String cleanStr = str.replaceAll("[^a-zA-Z0-9]", "").toLowerCase();
        int left = 0;
        int right = cleanStr.length() - 1;

        while (left < right) {
            if (cleanStr.charAt(left) != cleanStr.charAt(right)) {
                return false;
            }
            left++;
            right--;
        }
        return true;
    }

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        System.out.print("Enter a string: ");
        String inputString = scanner.nextLine();

        if (isPalindrome(inputString)) {
            System.out.println(inputString + " is a palindrome.");
        } else {
            System.out.println(inputString + " is not a palindrome.");
        }
        scanner.close();
    }
}
📤 Output:
Input: Racecar
Output: Racecar is a palindrome.
Input: A man, a plan, a canal: Panama
Output: A man, a plan, a canal: Panama is a palindrome.
Input: Hello
Output: Hello is not a palindrome.
Input: 12321
Output: 12321 is a palindrome.
Input: Madam, I'm Adam.
Output: Madam, I'm Adam. is a palindrome.
Input: Was it a car or a cat I saw?
Output: Was it a car or a cat I saw? is a palindrome.
Input: Never odd or even
Output: Never odd or even is a palindrome.
Input: Hello, World!
Output: Hello, World! is not a palindrome.
Input: Able was I, ere I saw Elba!
Output: Able was I, ere I saw Elba! is a palindrome.

💻 Method to Calculate Factorial
import java.util.Scanner;

public class FactorialCalculator {

    public static long calculateFactorial(int number) {
        if (number == 0) {
            return 1;
        } else {
            long factorial = 1;
            for (int i = 1; i <= number; i++) {
                factorial *= i;
            }
            return factorial;
        }
    }

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        System.out.print("Enter a non-negative integer: ");
        int num = scanner.nextInt();

        if (num < 0) {
            System.out.println("Factorial is not defined for negative numbers.");
        } else {
            long factorial = calculateFactorial(num);
            System.out.println("Factorial of " + num + " is: " + factorial);
        }
        scanner.close();
    }
}
📤 Output:
Input: 5
Output: Enter a non-negative integer: Factorial of 5 is: 120

Input: 0
Output: Enter a non-negative integer: Factorial of 0 is: 1

Input: -3
Output: Enter a non-negative integer: Factorial is not defined for negative numbers.

💻 Method to Check Prime Number
import java.util.Scanner;

public class PrimeNumberChecker {

    public static boolean isPrime(int number) {
        if (number <= 1) {
            return false;
        }
        for (int i = 2; i <= Math.sqrt(number); i++) {
            if (number % i == 0) {
                return false;
            }
        }
        return true;
    }

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        System.out.print("Enter a number: ");
        int num = scanner.nextInt();

        if (isPrime(num)) {
            System.out.println(num + " is a prime number.");
        } else {
            System.out.println(num + " is not a prime number.");
        }
        scanner.close();
    }
}
📤 Output:
Input: 17
Output: Enter a number: 17 is a prime number.

Input: 20
Output: Enter a number: 20 is not a prime number.

Input: 1
Output: Enter a number: 1 is not a prime number.

Input: 0
Output: Enter a number: 0 is not a prime number.

Input: -5
Output: Enter a number: -5 is not a prime number.

Methods

💻 Game Character Movement Simulation
import java.util.Scanner;

public class GameCharacterMovement {

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

        int xCoordinate = 0;
        int yCoordinate = 0;
        String move;

        do {
            System.out.print("Enter movement (N/S/E/W), or Q to quit: ");
            move = scanner.nextLine().toUpperCase();

            switch (move) {
                case "N":
                    yCoordinate++;
                    break;
                case "S":
                    yCoordinate--;
                    break;
                case "E":
                    xCoordinate++;
                    break;
                case "W":
                    xCoordinate--;
                    break;
                case "Q":
                    System.out.println("Exiting the game.");
                    break;
                default:
                    System.out.println("Invalid movement. Please use N, S, E, W or Q.");
            }

            System.out.println("Current position: (" + xCoordinate + ", " + yCoordinate + ")");

        } while (!move.equals("Q"));

        scanner.close();
    }
}
📤 Output:
Input: N
Output: Enter movement (N/S/E/W), or Q to quit:
Output: Current position: (0, 1)
Input: E
Output: Enter movement (N/S/E/W), or Q to quit:
Output: Current position: (1, 1)
Input: S
Output: Enter movement (N/S/E/W), or Q to quit:
Output: Current position: (1, 0)
Input: W
Output: Enter movement (N/S/E/W), or Q to quit:
Output: Current position: (0, 0)
Input: X
Output: Enter movement (N/S/E/W), or Q to quit:
Output: Invalid movement. Please use N, S, E, W or Q.
Output: Current position: (0, 0)
Input: Q
Output: Enter movement (N/S/E/W), or Q to quit:
Output: Exiting the game.
Output: Current position: (0, 0)

💻 Temperature Conversion Menu
import java.util.Scanner;

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

        do {
            System.out.println("Temperature Conversion Menu:");
            System.out.println("1. Celsius to Fahrenheit");
            System.out.println("2. Fahrenheit to Celsius");
            System.out.println("3. Exit");
            System.out.print("Enter your choice: ");
            choice = scanner.nextInt();

            if (choice == 1) {
                System.out.print("Enter temperature in Celsius: ");
                double celsius = scanner.nextDouble();
                double fahrenheit = (celsius * 9 / 5) + 32;
                System.out.println("Temperature in Fahrenheit: " + fahrenheit);
            } else if (choice == 2) {
                System.out.print("Enter temperature in Fahrenheit: ");
                double fahrenheit = scanner.nextDouble();
                double celsius = (fahrenheit - 32) * 5 / 9;
                System.out.println("Temperature in Celsius: " + celsius);
            } else if (choice == 3) {
                System.out.println("Exiting...");
            } else {
                System.out.println("Invalid choice. Please try again.");
            }
        } while (choice != 3);

        scanner.close();
    }
}
📤 Output:
Temperature Conversion Menu:
1. Celsius to Fahrenheit
2. Fahrenheit to Celsius
3. Exit
Enter your choice: Input: 1
Enter temperature in Celsius: Input: 25
Temperature in Fahrenheit: 77.0
Temperature Conversion Menu:
1. Celsius to Fahrenheit
2. Fahrenheit to Celsius
3. Exit
Enter your choice: Input: 2
Enter temperature in Fahrenheit: Input: 98.6
Temperature in Celsius: 37.0
Temperature Conversion Menu:
1. Celsius to Fahrenheit
2. Fahrenheit to Celsius
3. Exit
Enter your choice: Input: 3
Exiting...

💻 Simple ATM Machine Simulation
import java.util.Scanner;

public class SimpleAtmSimulation {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int balance = 10000; // Initial balance
        int choice;

        do {
            System.out.println("Welcome to the ATM!");
            System.out.println("1. Check Balance");
            System.out.println("2. Deposit");
            System.out.println("3. Withdraw");
            System.out.println("4. Exit");
            System.out.print("Enter your choice: ");

            choice = scanner.nextInt();

            switch (choice) {
                case 1:
                    System.out.println("Your balance is: " + balance);
                    break;
                case 2:
                    System.out.print("Enter amount to deposit: ");
                    int depositAmount = scanner.nextInt();
                    balance += depositAmount;
                    System.out.println("Deposit successful. New balance is: " + balance);
                    break;
                case 3:
                    System.out.print("Enter amount to withdraw: ");
                    int withdrawAmount = scanner.nextInt();
                    if (withdrawAmount <= balance) {
                        balance -= withdrawAmount;
                        System.out.println("Withdrawal successful. New balance is: " + balance);
                    } else {
                        System.out.println("Insufficient balance.");
                    }
                    break;
                case 4:
                    System.out.println("Thank you for using the ATM!");
                    break;
                default:
                    System.out.println("Invalid choice. Please try again.");
            }
        } while (choice != 4);

        scanner.close();
    }
}
📤 Output:
Welcome to the ATM!
1. Check Balance
2. Deposit
3. Withdraw
4. Exit
Enter your choice: Input: 1
Output: Your balance is: 10000
Welcome to the ATM!
1. Check Balance
2. Deposit
3. Withdraw
4. Exit
Enter your choice: Input: 2
Output: Enter amount to deposit: Input: 5000
Output: Deposit successful. New balance is: 15000
Welcome to the ATM!
1. Check Balance
2. Deposit
3. Withdraw
4. Exit
Enter your choice: Input: 3
Output: Enter amount to withdraw: Input: 2000
Output: Withdrawal successful. New balance is: 13000
Welcome to the ATM!
1. Check Balance
2. Deposit
3. Withdraw
4. Exit
Enter your choice: Input: 3
Output: Enter amount to withdraw: Input: 15000
Output: Insufficient balance.
Welcome to the ATM!
1. Check Balance
2. Deposit
3. Withdraw
4. Exit
Enter your choice: Input: 4
Output: Thank you for using the ATM!

💻 Password Validation
import java.util.Scanner;

public class PasswordValidationDoWhile {

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

        do {
            System.out.print("Enter your password (at least 8 characters): ");
            password = scanner.nextLine();

            isValid = password.length() >= 8;

            if (!isValid) {
                System.out.println("Password is too short. Please try again.");
            }
        } while (!isValid);

        System.out.println("Password accepted!");

        scanner.close();
    }
}
📤 Output:
Input: pass
Output: Enter your password (at least 8 characters): pass
Output: Password is too short. Please try again.
Input: password
Output: Enter your password (at least 8 characters): password
Output: Password accepted!

💻 Sum of Numbers until Negative is Entered
import java.util.Scanner;

public class SumUntilNegative {

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

        do {
            System.out.print("Enter a number (enter a negative number to stop): ");
            number = scanner.nextInt();

            if (number >= 0) {
                sum += number;
            }

        } while (number >= 0);

        System.out.println("Sum of the numbers entered (excluding the negative number): " + sum);

        scanner.close();
    }
}
📤 Output:
Input: 5
Input: 10
Input: 2
Input: -1
Output: Enter a number (enter a negative number to stop): Enter a number (enter a negative number to stop): Enter a number (enter a negative number to stop): Enter a number (enter a negative number to stop): Sum of the numbers entered (excluding the negative number): 17

💻 Continue until User Says 'No'
import java.util.Scanner;

public class ContinueUntilUserSaysNo {

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

        do {
            System.out.println("Doing some work...");
            System.out.print("Do you want to continue? (Yes/No): ");
            userInput = scanner.nextLine();
        } while (!userInput.equalsIgnoreCase("No"));

        System.out.println("Program terminated.");
        scanner.close();
    }
}
📤 Output:
Doing some work...
Do you want to continue? (Yes/No): Yes
Doing some work...
Do you want to continue? (Yes/No): yEs
Doing some work...
Do you want to continue? (Yes/No): NO
Program terminated.