Java Articles

Page 174 of 450

Java program to display Floyd\\\'s triangle

Pranay Arora
Pranay Arora
Updated on 18-Oct-2024 1K+ Views

In this article, we are going to see how to display Floyd’s Triangle using Java. Floyd's triangle is a popular right-angled triangular array consisting of natural numbers. It is formed by starting with the number 1 at the top of the triangle, and then incrementing each subsequent number by 1 as you move down the rows of the triangle. The first row contains only 1 number which is 1 itself and each subsequent row contains 1 more number than the previous row. The triangle has n rows where n can be any positive whole number. The total number of values in ...

Read More

Java program to fill elements in a char array

Arjun Thakur
Arjun Thakur
Updated on 18-Oct-2024 1K+ Views

In this article, we will fill elements in a char array using Java. We will be using the Arrays.fill() method to fill it with a specific character. This method allows us to assign a single character value to all elements in the array. We will fill the array with the character 'A' and then print the array using Arrays.toString() to display its contents in a readable format. Problem Statement Write a Java program to fill elements in a char array − Input charValue = 'A' Output The char array content is: [A, A, A, A, A] Steps to fill elements in a ...

Read More

Java Connection getAutoCommit() method with example

Rishi Raj
Rishi Raj
Updated on 18-Oct-2024 1K+ Views

In this program, we will establish a connection to a MySQL database and check the current auto-commit setting using the getAutoCommit() method from the Connection interface. We will first disable the auto-commit feature using setAutoCommit(false) and then retrieve the current auto-commit status with getAutoCommit() to verify if it has been successfully disabled. Steps to use the getAutoCommit() method Following are the steps to use the getAutoCommit() method − First, we will import the required java.sql.Connection and java.sql.DriverManager packages. We'll establish a connection to a MySQL database using the DriverManager.getConnection() method. ...

Read More

Java program to accept an integer from user and print it

Ankith Reddy
Ankith Reddy
Updated on 18-Oct-2024 2K+ Views

In this article, we will prompt the user to input an integer, and the entered value will be displayed back to them. To achieve this, we will use the Scanner class from java.util package, which allows us to read user input. Specifically, the nextInt() method of the Scanner class will be used to read the integer input from the user.Problem Statement Write a program in Java to accept an integer from the user and print it − Input Enter an integer: 2 Output Given integer is :: 2 Steps to accept an integer from the user and print it Following are ...

Read More

Java program to accept an integer from user and print it

Ankith Reddy
Ankith Reddy
Updated on 18-Oct-2024 2K+ Views

In this article, we will prompt the user to input an integer, and the entered value will be displayed back to them. To achieve this, we will use the Scanner class from java.util package, which allows us to read user input. Specifically, the nextInt() method of the Scanner class will be used to read the integer input from the user.Problem Statement Write a program in Java to accept an integer from the user and print it − Input Enter an integer: 2 Output Given integer is :: 2 Steps to accept an integer from the user and print it Following are ...

Read More

Java program to add long integers and check for overflow

karthikeya Boyini
karthikeya Boyini
Updated on 16-Oct-2024 1K+ Views

In this article, we will add two long integers in Java and check if the sum causes an overflow, which happens when the result exceeds the maximum value that a long data type can hold,  defined by the Long class as Long.MAX_VALUE. If the sum goes beyond this limit, an exception will be thrown to handle the overflow. Otherwise, the sum will be displayed as the result. Steps to add long integers and check for overflow Following are the steps to add long integers and check for overflow − First, we will define two long integers ...

Read More

Java program without making class

Arjun Thakur
Arjun Thakur
Updated on 16-Oct-2024 1K+ Views

Is it possible to create and run a Java program without any class? The answer is Yes. The trick is to use an enum instead of a Class.Enums are similar to classes, but instead of using the class keyword, we use enum to define them. An enum is used to represent a public static constant. It can have a static main method as well.  Steps to write Java program without making classFollowing are the steps to write a Java program without making class −We will start by defining an enum instead of a class. An enum typically represents constants, but it can also ...

Read More

Java program to print mirror lower star triangle pattern

AmitDiwan
AmitDiwan
Updated on 15-Oct-2024 828 Views

In this article, we will understand how to print a mirror lower star triangle pattern in Java. The program will use loops and print statements to get the output that we want, allowing us to get the pattern based on the number of rows specified by the user or predefined in the code. Problem Statement Write a Java program to print a mirror lower star triangle pattern. Below is a demonstration of the same − Input Enter the number of rows : 8 Output The mirror lower star triangle pattern : * * * * * * * * ...

Read More

Java program to reverse an array upto a given position

Samual Sam
Samual Sam
Updated on 15-Oct-2024 966 Views

In this article, we will reverse the elements of an array up to a specified position using Java. You will learn how the program takes an array, reverses the first part of it up to a given index, and prints the modified array. An array can be reversed upto the given position pos and the remaining array is unchanged.Problem Statement Write a Java program to reverse an array upto a given position.Input Array = 1 2 3 4 5 6 7 8 9 10 Position = 6 Output Modified array is: 6 5 4 3 2 1 7 8 9 ...

Read More

Java program to check if the string contains any character in the given set of characters

karthikeya Boyini
karthikeya Boyini
Updated on 15-Oct-2024 1K+ Views

In this article, we will learn to check if the string contains any character in the given set of characters in Java. We will iterate over the string and compare each character to a set of characters that we want to search for. If any match is found, the program will print the character and confirm that it is present in the string. Problem Statement Write a program in Java to check if the string contains any character in the given set of characters − Input str = abcde chSearch = 'b', 'c' Output Character b found in string abcde ...

Read More
Showing 1731–1740 of 4,496 articles
« Prev 1 172 173 174 175 176 450 Next »
Advertisements