Found 7442 Articles for Java

Java program to print the fibonacci series of a given number using while loop

Ankith Reddy
Updated on 23-Oct-2024 17:31:17

5K+ Views

In this article, we'll generate the Fibonacci series using a while loop in Java. The Fibonacci series is a sequence where each number is the sum of the two previous numbers, starting with two initial numbers, usually either (0, 1) or (1, 1). Here, we start with (1, 1) and use a while loop to print the next numbers in the sequence until a specified limit. Steps to print the Fibonacci series using while loop Following are the steps to print the Fibonacci series using the while loop − Define a class and initialize three variables: a ... Read More

Java program to print the fibonacci series of a given number using while loop

Ankith Reddy
Updated on 23-Oct-2024 17:31:17

5K+ Views

In this article, we'll generate the Fibonacci series using a while loop in Java. The Fibonacci series is a sequence where each number is the sum of the two previous numbers, starting with two initial numbers, usually either (0, 1) or (1, 1). Here, we start with (1, 1) and use a while loop to print the next numbers in the sequence until a specified limit. Steps to print the Fibonacci series using while loop Following are the steps to print the Fibonacci series using the while loop − Define a class and initialize three variables: a ... Read More

Java program to find whether given character is vowel or consonant

karthikeya Boyini
Updated on 13-Sep-2024 10:21:30

13K+ Views

In this article, we will learn to find whether a given character is a vowel or consonant using Java. In the English alphabet, the characters 'a', 'e', 'i', 'o', and 'u' are vowels and the remaining letters are consonants. To find whether the given letter is a vowel or consonant. Using a loop and or operator verify whether the given character is 'a' or 'e' or 'i' or 'o' or 'u' else it is consonant. Steps to find whether given character is vowel or consonant Following are the steps to find whether given character is a vowel or consonant− ... Read More

Java program to find whether given character is vowel or consonant

karthikeya Boyini
Updated on 13-Sep-2024 10:21:30

13K+ Views

In this article, we will learn to find whether a given character is a vowel or consonant using Java. In the English alphabet, the characters 'a', 'e', 'i', 'o', and 'u' are vowels and the remaining letters are consonants. To find whether the given letter is a vowel or consonant. Using a loop and or operator verify whether the given character is 'a' or 'e' or 'i' or 'o' or 'u' else it is consonant. Steps to find whether given character is vowel or consonant Following are the steps to find whether given character is a vowel or consonant− ... Read More

Java program to calculate the factorial of a given number using while loop

Samual Sam
Updated on 18-Jul-2024 14:22:45

4K+ Views

The factorial of a number is a fundamental concept in mathematics, representing the product of all positive integers up to that number. Calculating the factorial of a given number is a common problem in programming, and Java provides a straightforward way to achieve this using a while loop. A factorial of a particular number (n) is the product of all the numbers from 0 to n (including n) i.e. factorial of the number 5 will be 1*2*3*4*5 = 120. Problem Statement Given a number write a Java program to calculate the factorial using while loop. Input ... Read More

Java program to calculate the factorial of a given number using while loop

Samual Sam
Updated on 18-Jul-2024 14:22:45

4K+ Views

The factorial of a number is a fundamental concept in mathematics, representing the product of all positive integers up to that number. Calculating the factorial of a given number is a common problem in programming, and Java provides a straightforward way to achieve this using a while loop. A factorial of a particular number (n) is the product of all the numbers from 0 to n (including n) i.e. factorial of the number 5 will be 1*2*3*4*5 = 120. Problem Statement Given a number write a Java program to calculate the factorial using while loop. Input ... Read More

Java program to swap two numbers using XOR operator

Arjun Thakur
Updated on 05-Nov-2024 22:02:32

622 Views

In this article, we will learn how to swap two numbers using the XOR bitwise operator in Java. The XOR operator is a powerful tool that allows you to perform bitwise operations, and one of its interesting properties is that it can be used to swap two variables without using a temporary variable. This method is efficient and can be used when you need a fast swapping mechanism. Problem StatementGiven two integers, write a Java program to swap their values using the XOR operator.Input Two integers are provided by the user.Output The values of the two integers after swapping. ... Read More

Java program to swap two numbers using XOR operator

Arjun Thakur
Updated on 05-Nov-2024 22:02:32

622 Views

In this article, we will learn how to swap two numbers using the XOR bitwise operator in Java. The XOR operator is a powerful tool that allows you to perform bitwise operations, and one of its interesting properties is that it can be used to swap two variables without using a temporary variable. This method is efficient and can be used when you need a fast swapping mechanism. Problem StatementGiven two integers, write a Java program to swap their values using the XOR operator.Input Two integers are provided by the user.Output The values of the two integers after swapping. ... Read More

Java program to find the circumference of a circle

Ankith Reddy
Updated on 24-Jun-2024 15:46:10

9K+ Views

The circumference of a circle is double the product of its radius and the value of PI. Therefore, to calculate the circumference of a circleGet the radius of the circle form the user.Calculate the productPrint the final result.Example: Finding the circumference of a circle import java.util.Scanner; public class CircumfrenceOfCircle {    public static void main(String args[]){       int radius;       double circumference;       Scanner sc = new Scanner(System.in);       System.out.println("Enter the radius of the circle ::");       radius = sc.nextInt();       circumference = Math.PI*2*radius;       System.out.println("Circumference ... Read More

Java program to find the circumference of a circle

Ankith Reddy
Updated on 24-Jun-2024 15:46:10

9K+ Views

The circumference of a circle is double the product of its radius and the value of PI. Therefore, to calculate the circumference of a circleGet the radius of the circle form the user.Calculate the productPrint the final result.Example: Finding the circumference of a circle import java.util.Scanner; public class CircumfrenceOfCircle {    public static void main(String args[]){       int radius;       double circumference;       Scanner sc = new Scanner(System.in);       System.out.println("Enter the radius of the circle ::");       radius = sc.nextInt();       circumference = Math.PI*2*radius;       System.out.println("Circumference ... Read More

Advertisements