first digit of a number

In this article, we are going to write code for finding the first digit of a number. Example:- if number = 7122344 then output will be 7. Steps:- Java code to find last digit of a number:- Output:- You can use the same logic to find the first digit of a number using other programming … Read more

GCD of two numbers using java.

In this article, we are going to find the GCD(Greatest Common Divisor) of two numbers using java code. Example:- if a=10(first number), b=15(second number) then GCD of a and b will be 5. Steps:- Java code to find GCD of two numbers. Output:- You can use the same logic to find the GCD of two … Read more

LCM in java

In this article we going to calculate LCM of two numbers using java code. Example:- if a=10(first number), b=15(Second number) then answer=30, it is the LCM of 10 and 15. Steps:- Java code to find LCM of two numbers. Output:- You can use the same logic to find the LCM of two numbers using other … Read more

Factorial using java

In this article, we are going to print factorial of any number using java code. Example :-if n=5, solution:- 5*4*3*2*1=120 What is factorial? The factorial of any number is equal to the product of all positive numbers less then or equals to that number. Steps:- Java code to print factorial:- Output:- You can use the … Read more

Triangle pattern program using java

In this article, we are going to print java code to print triangle pattern. Example if n=4. Steps:- Take the input for number of lines in a triangle, from the user using scanner. Run a loop for number of lines. Inside the previous loop run another loop for printing * which equals to line’s number. … Read more

Inverted triangle pattern using java

In this article we going to print inverted triangle pattern using java code. Example:- if n=4 (n is the number of lines in triangle.) Steps:- Take input from the user for the height of the triangle using a scanner. Run a loop for all the rows in the triangle. Inside loop run another loop for … Read more

Square pattern in java

In this article we are going to print square pattern using java code. Example:- if n = 4 Steps:- Take input for row and column from user using scanner Run a loop for rows from i= 1to i<=n. inside first loop run another loop for column from j=1 to j<=n. and print *. After termination … Read more

Program to counts digits in a number

In this article we are going to count digits in a given number Example:- if number is 23455, then the output will be 5. because the total number of digits is 5 in a given number. Steps:- First take input from the user by using a scanner. declare a variable to count the digits. run … Read more