es
Feedback
Tech Jargon - Decoded

Tech Jargon - Decoded

Ir al canal en 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

Mostrar más
2 018
Suscriptores
Sin datos24 horas
-77 días
-4030 días
Archivo de publicaciones
💻 Sum of Digits of a Number
import java.util.Scanner;

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

        for (int i = number; i != 0; i /= 10) {
            int digit = i % 10;
            sum += digit;
        }

        System.out.println("Sum of digits: " + sum);
        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

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

Input: 100
Output: Enter a number: Sum of digits: 1

💻 Print Multiplication Table
import java.util.Scanner;

public class MultiplicationTable {

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

        System.out.print("Enter the number for the multiplication table: ");
        int number = scanner.nextInt();

        System.out.print("Enter the limit till where you want the table: ");
        int limit = scanner.nextInt();

        for (int i = 1; i <= limit; i++) {
            System.out.println(number + " * " + i + " = " + (number * i));
        }

        scanner.close();
    }
}
📤 Output:
Input: 5
Input: 10
Output: 5 * 1 = 5
5 * 2 = 10
5 * 3 = 15
5 * 4 = 20
5 * 5 = 25
5 * 6 = 30
5 * 7 = 35
5 * 8 = 40
5 * 9 = 45
5 * 10 = 50

Loops - For

💻 Find GCD/HCF of Two Numbers
import java.util.Scanner;

public class GCDWhileLoop {

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

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

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

        while (number2 != 0) {
            int temp = number2;
            number2 = number1 % number2;
            number1 = temp;
        }

        System.out.println("GCD is: " + number1);
        scanner.close();
    }
}
📤 Output:
Input: 12
Input: 8
Output: Enter first number: Enter second number: GCD is: 4

Input: 48
Input: 18
Output: Enter first number: Enter second number: GCD is: 6

Input: 98
Input: 56
Output: Enter first number: Enter second number: GCD is: 14

💻 Find First N Fibonacci Numbers
import java.util.Scanner;

public class FibonacciSeriesWhile {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        System.out.print("Enter the value of N: ");
        int n = scanner.nextInt();

        int firstNumber = 0;
        int secondNumber = 1;

        int i = 1;
        while (i <= n) {
            System.out.print(firstNumber + " ");

            int nextNumber = firstNumber + secondNumber;
            firstNumber = secondNumber;
            secondNumber = nextNumber;
            i++;
        }
        System.out.println();
        scanner.close();
    }
}
📤 Output:
Input: 5
Output: Enter the value of N: 0 1 1 2 3
Input: 10
Output: Enter the value of N: 0 1 1 2 3 5 8 13 21 34
Input: 1
Output: Enter the value of N: 0

💻 Print Multiplication Table
import java.util.Scanner;

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

        System.out.print("Enter the number for the multiplication table: ");
        int number = scanner.nextInt();

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

        int i = 1;
        while (i <= limit) {
            System.out.println(number + " * " + i + " = " + (number * i));
            i++;
        }

        scanner.close();
    }
}
📤 Output:
Input: 5
Input: 10
Output: Enter the number for the multiplication table: Enter the limit for the multiplication table: 5 * 1 = 5
5 * 2 = 10
5 * 3 = 15
5 * 4 = 20
5 * 5 = 25
5 * 6 = 30
5 * 7 = 35
5 * 8 = 40
5 * 9 = 45
5 * 10 = 50

💻 Check if Number is Armstrong
import java.util.Scanner;

public class ArmstrongNumberChecker {

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

        while (number > 0) {
            int digit = number % 10;
            sum += Math.pow(digit, numberOfDigits);
            number /= 10;
        }

        if (sum == originalNumber) {
            System.out.println(originalNumber + " is an Armstrong number.");
        } else {
            System.out.println(originalNumber + " 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: 1634
Output: 1634 is an Armstrong number.

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

💻 Check if Number is Palindrome
import java.util.Scanner;

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

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

        int originalNumber = number;
        int reversedNumber = 0;

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

        if (originalNumber == reversedNumber) {
            System.out.println(originalNumber + " is a palindrome.");
        } else {
            System.out.println(originalNumber + " is not a palindrome.");
        }

        scanner.close();
    }
}
📤 Output:
Input: 121
Output: 121 is a palindrome.

Input: 123
Output: 123 is not a palindrome.

Input: 12321
Output: 12321 is a palindrome.

Input: 10
Output: 10 is not a palindrome.

💻 Sum of Digits of a Number
import java.util.Scanner;

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

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

        int sum = 0;
        int tempNumber = number;

        while (tempNumber != 0) {
            int lastDigit = tempNumber % 10;
            sum += lastDigit;
            tempNumber /= 10; // integer division
        }

        System.out.println("Sum of digits of " + number + " is: " + sum);

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

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

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

Input: 5
Output: Enter a number: Sum of digits of 5 is: 5

💻 Count Digits in a Number
import java.util.Scanner;

public class CountDigitsInNumber {

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

        System.out.print("Enter a number: ");
        int number = input.nextInt();

        int count = 0;
        int originalNumber = number; // Store the original number

        if (number == 0) {
            count = 1; // Special case for 0
        } else {
            while (number != 0) {
                number = number / 10;
                count++;
            }
        }

        System.out.println("The number of digits in " + originalNumber + " is: " + count);

        input.close();
    }
}
📤 Output:
Input: 12345
Output: Enter a number: The number of digits in 12345 is: 5

Input: 0
Output: Enter a number: The number of digits in 0 is: 1

Input: 9
Output: Enter a number: The number of digits in 9 is: 1

Input: -123
Output: Enter a number: The number of digits in -123 is: 3

💻 Reverse a Number
import java.util.Scanner;

public class ReverseNumberWhile {

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

        int reversedNumber = 0;

        while (number != 0) {
            int remainder = number % 10; // Get the last digit
            reversedNumber = reversedNumber * 10 + remainder; // Append the digit to reversedNumber
            number = number / 10; // Remove the last digit from number
        }

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

Input: 121
Output: Enter a number: Reversed Number: 121

Input: 100
Output: Enter a number: Reversed Number: 1

Input: -123
Output: Enter a number: Reversed Number: -321

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

💻 Factorial of a Number
import java.util.Scanner;

public class FactorialWhileLoop {

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

        System.out.print("Enter a non-negative integer: ");
        int number = scanner.nextInt();

        long factorial = 1;
        int i = 1;

        if (number < 0) {
            System.out.println("Factorial is not defined for negative numbers.");
        } else {
            while (i <= number) {
                factorial *= i;
                i++;
            }
            System.out.println("Factorial of " + number + " is: " + factorial);
        }

        scanner.close();
    }
}
📤 Output:
Input: 5
Output: Factorial of 5 is: 120

Input: 0
Output: Factorial of 0 is: 1

Input: -3
Output: Factorial is not defined for negative numbers.

💻 Sum of Odd Numbers from 1 to N
import java.util.Scanner;

public class SumOfOddNumbers {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        System.out.print("Enter the value of N: ");
        int n = scanner.nextInt();

        int sum = 0;
        int i = 1;

        while (i <= n) {
            if (i % 2 != 0) {
                sum += i;
            }
            i++;
        }

        System.out.println("Sum of odd numbers from 1 to " + n + " is: " + sum);
        scanner.close();
    }
}
📤 Output:
Input: 10
Output: Sum of odd numbers from 1 to 10 is: 25

Input: 5
Output: Sum of odd numbers from 1 to 5 is: 9

Input: 1
Output: Sum of odd numbers from 1 to 1 is: 1

💻 Sum of Even Numbers from 1 to N
import java.util.Scanner;

public class SumOfEvenNumbers {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        System.out.print("Enter the value of N: ");
        int n = scanner.nextInt();

        int sum = 0;
        int i = 2;

        while (i <= n) {
            if (i % 2 == 0) {
                sum += i;
            }
            i++;
        }

        System.out.println("Sum of even numbers from 1 to " + n + " is: " + sum);
        scanner.close();
    }
}
📤 Output:
Input: 10
Output: Enter the value of N: Sum of even numbers from 1 to 10 is: 30

Input: 15
Output: Enter the value of N: Sum of even numbers from 1 to 15 is: 56

Input: 2
Output: Enter the value of N: Sum of even numbers from 1 to 2 is: 2

Input: 1
Output: Enter the value of N: Sum of even numbers from 1 to 1 is: 0

Solve LeetCode problems consistently in structured manner Join here👇 https://t.me/+L6Z9gjVIVEQ4NmRl

💻 Sum of First N Natural Numbers
import java.util.Scanner;

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

        System.out.print("Enter the value of N: ");
        int n = scanner.nextInt();

        int sum = 0;
        int i = 1;

        while (i <= n) {
            sum = sum + i;
            i++;
        }

        System.out.println("Sum of first " + n + " natural numbers is: " + sum);

        scanner.close();
    }
}
📤 Output:
Input: 5
Output: Enter the value of N: Sum of first 5 natural numbers is: 15

Input: 10
Output: Enter the value of N: Sum of first 10 natural numbers is: 55

Input: 1
Output: Enter the value of N: Sum of first 1 natural numbers is: 1

Input: 0
Output: Enter the value of N: Sum of first 0 natural numbers is: 0

💻 Print Odd Numbers from 1 to N
import java.util.Scanner;

public class PrintOddNumbers {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        System.out.print("Enter the value of N: ");
        int n = scanner.nextInt();

        int i = 1;
        while (i <= n) {
            if (i % 2 != 0) {
                System.out.println(i);
            }
            i++;
        }
        scanner.close();
    }
}
📤 Output:
Input: 10
Output: Enter the value of N:
1
3
5
7
9
Input: 5
Output: Enter the value of N:
1
3
5
Input: 1
Output: Enter the value of N:
1
Input: 2
Output: Enter the value of N:
1

💻 Print Even Numbers from 1 to N
import java.util.Scanner;

public class PrintEvenNumbers {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        System.out.print("Enter the value of N: ");
        int n = scanner.nextInt();

        int i = 2;
        while (i <= n) {
            System.out.println(i);
            i += 2;
        }

        scanner.close();
    }
}
📤 Output:
Input: 10
Output: Enter the value of N:
2
4
6
8
10
Input: 15
Output: Enter the value of N:
2
4
6
8
10
12
14
Input: 1
Output: Enter the value of N:

Input: 2
Output: Enter the value of N:
2
Input: 0
Output: Enter the value of N:

💻 Print Numbers from N to 1
import java.util.Scanner;

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

        int i = number;
        while (i >= 1) {
            System.out.println(i);
            i--;
        }

        scanner.close();
    }
}
📤 Output:
Input: 5
Output: 5
4
3
2
1

💻 Print Numbers from 1 to N
import java.util.Scanner;

public class PrintNumbers {

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

        int i = 1;
        while (i <= n) {
            System.out.println(i);
            i++;
        }

        input.close();
    }
}
📤 Output:
Input: 5
Output:
Enter a number (N): 1
2
3
4
5