Java Articles

Page 178 of 450

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

Arjun Thakur
Arjun Thakur
Updated on 11-Dec-2024 2K+ Views

In this article, we’ll learn to find the largest of three numbers using the ternary operator in Java. This simple yet effective approach allows you to write concise and readable code. Finding the largest of three numbers is a common programming task, and Java provides an efficient way to do this using the ternary operator. This concise approach reduces code complexity while maintaining readability. What is the Ternary Operator in Java?  The ternary operator is a shorthand for if-else statements in Java. It uses the syntax: condition ? value_if_true : value_if_false This operator is useful for simple conditional checks and ...

Read More

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

Arjun Thakur
Arjun Thakur
Updated on 11-Dec-2024 2K+ Views

In this article, we’ll learn to find the largest of three numbers using the ternary operator in Java. This simple yet effective approach allows you to write concise and readable code. Finding the largest of three numbers is a common programming task, and Java provides an efficient way to do this using the ternary operator. This concise approach reduces code complexity while maintaining readability. What is the Ternary Operator in Java?  The ternary operator is a shorthand for if-else statements in Java. It uses the syntax: condition ? value_if_true : value_if_false This operator is useful for simple conditional checks and ...

Read More

Java Connection setSavepoint() method with example

Alshifa Hasnain
Alshifa Hasnain
Updated on 11-Dec-2024 1K+ Views

When working with databases in Java, there are scenarios where you might want to perform complex transactions involving multiple steps. To maintain control and flexibility during such operations, Savepoints come into play. The setSavepoint() method in the java.sql.Connection interface allows you to create a savepoint within a transaction, providing a mechanism to roll back to a specific point if needed. What is Savepoint? A Savepoint is a marker within a database transaction. It enables partial rollbacks, meaning you can undo a subset of changes made during a transaction without affecting the entire operation. This is particularly useful in scenarios where ...

Read More

Find All the Subarrays of a Given Array in Java

Mr. Satyabrata
Mr. Satyabrata
Updated on 10-Dec-2024 56K+ Views

An array is a linear data structure in which elements are stored in contiguous memory locations. As per problem statement, we have to find all the subarrays of a given array. Subarrays are part or a section of an array. When we talk about all subarrays of an array, we talk about the total number of combinations that can be made using all the elements of the array without repeating. Let’s explore the article to see how it can be done by using Java programming language. To Show you Some Instances Instance-1 Suppose we have the below array [10, ...

Read More

Multilevel inheritance in Java

Govinda Sai
Govinda Sai
Updated on 10-Dec-2024 90K+ Views

Multilevel inheritance - A class inherits properties from a class which again has inherits properties. Example class Shape {    public void display() {       System.out.println("Inside display");    } } class Rectangle extends Shape {    public void area() {       System.out.println("Inside area");    } } class Cube extends Rectangle {    public void volume() {       System.out.println("Inside volume");    } } public class Tester {    public static void main(String[] arguments) {       Cube cube = new Cube();       cube.display();       cube.area();       cube.volume();    } } Output Inside display Inside area Inside volume Read Also: Java Inheritance

Read More

Multilevel inheritance in Java

Govinda Sai
Govinda Sai
Updated on 10-Dec-2024 90K+ Views

Multilevel inheritance - A class inherits properties from a class which again has inherits properties. Example class Shape {    public void display() {       System.out.println("Inside display");    } } class Rectangle extends Shape {    public void area() {       System.out.println("Inside area");    } } class Cube extends Rectangle {    public void volume() {       System.out.println("Inside volume");    } } public class Tester {    public static void main(String[] arguments) {       Cube cube = new Cube();       cube.display();       cube.area();       cube.volume();    } } Output Inside display Inside area Inside volume Read Also: Java Inheritance

Read More

Multilevel inheritance in Java

Govinda Sai
Govinda Sai
Updated on 10-Dec-2024 90K+ Views

Multilevel inheritance - A class inherits properties from a class which again has inherits properties. Example class Shape {    public void display() {       System.out.println("Inside display");    } } class Rectangle extends Shape {    public void area() {       System.out.println("Inside area");    } } class Cube extends Rectangle {    public void volume() {       System.out.println("Inside volume");    } } public class Tester {    public static void main(String[] arguments) {       Cube cube = new Cube();       cube.display();       cube.area();       cube.volume();    } } Output Inside display Inside area Inside volume Read Also: Java Inheritance

Read More

Java program to find minimum sum of factors of a number

AmitDiwan
AmitDiwan
Updated on 09-Dec-2024 547 Views

In mathematics, the factors of a number are the integers that divide the number without leaving a remainder. For a given number, finding the minimum sum of its factors involves identifying a pair of factors whose sum is the smallest among all possible factor pairs. In this article, we will learn to find the minimum sum of factors of a number we will be using the Integer class and Math class in Java − Integer class The Java Integer class serves as a wrapper for the primitive int type, encapsulating a single integer value within an object. For Integer.MAX_VALUE, which provides ...

Read More

Java Program for Gnome Sort

AmitDiwan
AmitDiwan
Updated on 04-Dec-2024 512 Views

Gnome Sort, also known as Stupid Sort, is a simple sorting algorithm that works by iterating through a list, comparing adjacent elements, and swapping them if they are in the wrong order. If a swap occurs, the algorithm moves one step backward to recheck the order, otherwise, it moves forward. This process continues until the array is sorted. In this article, we will explain the working of Gnome Sort using Java. Gnome Sort Approach Start from the first element. Compare the current element with the previous one: ...

Read More

Java program to check if all digits of a number divide it

AmitDiwan
AmitDiwan
Updated on 03-Dec-2024 387 Views

The given article involves determining if all digits of a positive integer can divide the number without leaving a remainder. If any digit is zero or does not divide the number the result is false; otherwise, it is true using Java. This can be solved using two approaches: the Naive-Based Approach, which relies on arithmetic operations, and the String-Based Approach, which uses string manipulation for digit processing. Both methods ensure each digit meets the divisibility condition efficiently. Approaches to Check If All Digits of a Number Divide It Following are the different approaches to check if all digits of a ...

Read More
Showing 1771–1780 of 4,498 articles
« Prev 1 176 177 178 179 180 450 Next »
Advertisements