Found 7442 Articles for Java

Java program to find smallest of the three numbers using ternary operators

Shriansh Kumar
Updated on 11-Sep-2024 11:02:27

2K+ Views

To find the smallest from three given numbers using ternary operator, create a temporary variable to store the result of first comparison operation between two numbers. Then, perform second comparison operation between the result of first operation (i.e. temp) and third number to get the final result. Let's understand the problem statement with an example − Example Scenario: Input: nums = 20, 35, 10; Output: res = 10 What is Ternary Operator? The conditional operator in Java is also known as the ternary operator. This operator consists of three operands and is used to evaluate Boolean expressions. The goal ... Read More

Java program to find smallest of the three numbers using ternary operators

Shriansh Kumar
Updated on 11-Sep-2024 11:02:27

2K+ Views

To find the smallest from three given numbers using ternary operator, create a temporary variable to store the result of first comparison operation between two numbers. Then, perform second comparison operation between the result of first operation (i.e. temp) and third number to get the final result. Let's understand the problem statement with an example − Example Scenario: Input: nums = 20, 35, 10; Output: res = 10 What is Ternary Operator? The conditional operator in Java is also known as the ternary operator. This operator consists of three operands and is used to evaluate Boolean expressions. The goal ... Read More

Java program to calculate student grades

karthikeya Boyini
Updated on 13-Mar-2020 09:57:09

17K+ Views

The following program accepts average from the user, calculates the grade and prints it.Examplepublic class CalculateStudentGrades {    public static void main(String args[]) {       Scanner sc = new Scanner(System.in);       System.out.println("Enter average of your marks (less than 100)::");       int average = sc.nextInt();       char grade;       if(average>=80){          grade = 'A';       }else if(average>=60 && average=40 && average

Java program to calculate student grades

karthikeya Boyini
Updated on 13-Mar-2020 09:57:09

17K+ Views

The following program accepts average from the user, calculates the grade and prints it.Examplepublic class CalculateStudentGrades {    public static void main(String args[]) {       Scanner sc = new Scanner(System.in);       System.out.println("Enter average of your marks (less than 100)::");       int average = sc.nextInt();       char grade;       if(average>=80){          grade = 'A';       }else if(average>=60 && average=40 && average

Java program to reverse an array

Alshifa Hasnain
Updated on 20-Jan-2025 19:19:59

1K+ Views

In this article, we will learn to reverse an array in Java. Reversing an array is a classic problem that helps understand essential concepts like data structures and in-place manipulation. This operation is commonly required in programming tasks, such as data transformations, algorithm implementations, and solving logical problems. Problem Statement Reversing an array involves rearranging its elements so that the first element becomes the last, the second becomes the second-to-last, and so on. Input int[] myArray = {23, 93, 56, 92, 39}; Output {39, 92, 56, 93, 23} Different Approaches Following are the two different approaches to reverse an array ... Read More

Java program to reverse an array

Alshifa Hasnain
Updated on 20-Jan-2025 19:19:59

1K+ Views

In this article, we will learn to reverse an array in Java. Reversing an array is a classic problem that helps understand essential concepts like data structures and in-place manipulation. This operation is commonly required in programming tasks, such as data transformations, algorithm implementations, and solving logical problems. Problem Statement Reversing an array involves rearranging its elements so that the first element becomes the last, the second becomes the second-to-last, and so on. Input int[] myArray = {23, 93, 56, 92, 39}; Output {39, 92, 56, 93, 23} Different Approaches Following are the two different approaches to reverse an array ... Read More

Java program to find whether given character is vowel or consonant using switch case

George John
Updated on 13-Sep-2024 10:21:14

3K+ Views

A switch statement in Java allows a variable to be tested for equality against a list of values. Each value is called a case, and the variable being switched on is checked for each case. To verify whether given character is a vowel read a character from the user into a variable (say ch). Problem Statement Given a character, write a Java program to determine whether it is a vowel or a consonant using a switch statement. Input Enter a character : a Output Given character is an vowel Steps to check whether given character is vowel or ... Read More

Java program to find whether given character is vowel or consonant using switch case

George John
Updated on 13-Sep-2024 10:21:14

3K+ Views

A switch statement in Java allows a variable to be tested for equality against a list of values. Each value is called a case, and the variable being switched on is checked for each case. To verify whether given character is a vowel read a character from the user into a variable (say ch). Problem Statement Given a character, write a Java program to determine whether it is a vowel or a consonant using a switch statement. Input Enter a character : a Output Given character is an vowel Steps to check whether given character is vowel or ... Read More

Java program to Largest number among three numbers

Lakshmi Srinivas
Updated on 13-Mar-2020 09:53:45

4K+ Views

Comparing three integer variables is one of the simplest programs you can write at ease. Take two integer variables, say A, B& C Assign values to variables If A is greater than B & C, Display A is the largest value If B is greater than A & C, Display B is the largest value If C is greater than A & B, Display A is the largest value Otherwise, Display A, B & C are not unique valuesExampleimport java.util.Scanner; public class LargestOfThreeNumbers {    public static void main(String args[]){       Scanner sc =new Scanner(System.in);       System.out.println("Enter 1st number :");     ... Read More

Java program to Largest number among three numbers

Lakshmi Srinivas
Updated on 13-Mar-2020 09:53:45

4K+ Views

Comparing three integer variables is one of the simplest programs you can write at ease. Take two integer variables, say A, B& C Assign values to variables If A is greater than B & C, Display A is the largest value If B is greater than A & C, Display B is the largest value If C is greater than A & B, Display A is the largest value Otherwise, Display A, B & C are not unique valuesExampleimport java.util.Scanner; public class LargestOfThreeNumbers {    public static void main(String args[]){       Scanner sc =new Scanner(System.in);       System.out.println("Enter 1st number :");     ... Read More

Advertisements