Found 7442 Articles for Java

Java program to print a multiplication table for any number

Shriansh Kumar
Updated on 01-Aug-2024 10:58:04

2K+ Views

For a given integer number, write a Java program to print its multiplication table. In mathematics, a multiplication table shows the product of two numbers. Printing Multiplication Table using for Loop In Java, a for loop is used when a specific block of code needs to be executed multiple times. Here, we will run this loop 10 times and increment the loop variable by one with each iteration. During this iteration, multiply the given integer value with the current value of the loop variable to get the multiplication table. Example Following is a Java program which prints the multiplication ... Read More

Java program to print a multiplication table for any number

Shriansh Kumar
Updated on 01-Aug-2024 10:58:04

2K+ Views

For a given integer number, write a Java program to print its multiplication table. In mathematics, a multiplication table shows the product of two numbers. Printing Multiplication Table using for Loop In Java, a for loop is used when a specific block of code needs to be executed multiple times. Here, we will run this loop 10 times and increment the loop variable by one with each iteration. During this iteration, multiply the given integer value with the current value of the loop variable to get the multiplication table. Example Following is a Java program which prints the multiplication ... Read More

Java program to find the LCM of two numbers

karthikeya Boyini
Updated on 23-Oct-2024 17:35:36

8K+ Views

In this article, we will learn to find the LCM of two numbers using Java. L.C.M. or Least Common Multiple of two values is the smallest positive value which is the multiple of both values. For example, multiples of 3 and 4 are: 3 → 3, 6, 9, 12, 15 ... 4 → 4, 8, 12, 16, 20 ... The smallest multiple of both is 12, hence the LCM of 3 and 4 is 12.We will learn through two different methods to solve this: an incremental method and a formula-based approach using the Greatest Common Divisor (GCD).  Problem Statement Write ... Read More

Java program to find the LCM of two numbers

karthikeya Boyini
Updated on 23-Oct-2024 17:35:36

8K+ Views

In this article, we will learn to find the LCM of two numbers using Java. L.C.M. or Least Common Multiple of two values is the smallest positive value which is the multiple of both values. For example, multiples of 3 and 4 are: 3 → 3, 6, 9, 12, 15 ... 4 → 4, 8, 12, 16, 20 ... The smallest multiple of both is 12, hence the LCM of 3 and 4 is 12.We will learn through two different methods to solve this: an incremental method and a formula-based approach using the Greatest Common Divisor (GCD).  Problem Statement Write ... Read More

Java program to find the GCD or HCF of two numbers

Chandu yadav
Updated on 14-Jun-2024 13:21:32

36K+ Views

An H.C.F or Highest Common Factor, is the largest common factor of two or more values.For example factors of 12 and 16 are −12 → 1, 2, 3, 4, 6, 12 16 → 1, 2, 4, 8, 16The common factors are 1, 2, 4 and the highest common factor is 4.AlgorithmDefine two variables - A, BSet loop from 1 to max of A, BCheck if both are completely divided by same loop number, if yes, store itDisplay the stored number is HCFExample: Using Java for loop import java.util.Scanner; public class GCDOfTwoNumbers {    public static void main(String args[]){   ... Read More

Java program to find the GCD or HCF of two numbers

Chandu yadav
Updated on 14-Jun-2024 13:21:32

36K+ Views

An H.C.F or Highest Common Factor, is the largest common factor of two or more values.For example factors of 12 and 16 are −12 → 1, 2, 3, 4, 6, 12 16 → 1, 2, 4, 8, 16The common factors are 1, 2, 4 and the highest common factor is 4.AlgorithmDefine two variables - A, BSet loop from 1 to max of A, BCheck if both are completely divided by same loop number, if yes, store itDisplay the stored number is HCFExample: Using Java for loop import java.util.Scanner; public class GCDOfTwoNumbers {    public static void main(String args[]){   ... Read More

Java program to display English alphabets

Samual Sam
Updated on 13-Mar-2020 10:20:56

411 Views

Following is an example to display English alphabets A to Z.ExampleLive Demopublic class DisplayingAtoZ {    public static void main(String args[]){       char ch;       System.out.println("List of alphabets are ::");       for(ch = 'A'; ch

Java program to display English alphabets

Samual Sam
Updated on 13-Mar-2020 10:20:56

411 Views

Following is an example to display English alphabets A to Z.ExampleLive Demopublic class DisplayingAtoZ {    public static void main(String args[]){       char ch;       System.out.println("List of alphabets are ::");       for(ch = 'A'; ch

Java program to Count the number of digits in a given integer

Shriansh Kumar
Updated on 11-Sep-2024 10:36:31

22K+ Views

Suppose an integer number is given as an input, our task is to write a Java program to count the number of digits in that integer. For this problem, create a counter variable and initialize it with 0. Divide the given integer value with 10 till the integer becomes 0 and increment the counter variable for each turn. Using while Loop A while loop in Java is a control flow statement that allows code to be executed repeatedly based on a given Boolean condition. For the given problem, we use this loop to check whether the specified integer value is ... Read More

Java program to Count the number of digits in a given integer

Shriansh Kumar
Updated on 11-Sep-2024 10:36:31

22K+ Views

Suppose an integer number is given as an input, our task is to write a Java program to count the number of digits in that integer. For this problem, create a counter variable and initialize it with 0. Divide the given integer value with 10 till the integer becomes 0 and increment the counter variable for each turn. Using while Loop A while loop in Java is a control flow statement that allows code to be executed repeatedly based on a given Boolean condition. For the given problem, we use this loop to check whether the specified integer value is ... Read More

Advertisements