Java Program to Add Characters to a String

Shriansh Kumar
Updated on 31-May-2024 14:39:39

6K+ Views

Java provides different ways to add characters to a string. We can add characters in the beginning or at the end or at any position according to the need. In this article we are going to see three approaches to do so − Using ‘+’ operator Using methods of StringBuffer and StringBuilder class Using substring() method Approach 1: Using ‘+’ Operator In this section, we will add a character to a string using the concatenation operator. Example public class Main { public static void main(String[] args) { String ... Read More

Java Tricky Output Questions

Way2Class
Updated on 31-May-2024 14:14:28

4K+ Views

Java Tricky Output Questions that are difficult to answer call for more work to be put into them. We will fall short if we attempt to respond to a challenging topic using common sense since such questions need specialized understanding. The majority of challenging java problems are based on perplexing ideas like loops, multi-threading, overloading, overriding, etc. Even when a question isn’t particularly challenging, we occasionally have trouble solving it. Despite the fact that the answer to the question is straightforward, we occasionally write code carelessly. Even if we don’t know the solution, we can still use analytical thinking ... Read More

Java Program to Handle Divide by Zero and Multiple Exceptions

Shiva Keerthi
Updated on 31-May-2024 14:07:14

6K+ Views

Exceptions are the unusual events which disrupt the normal flow of execution of a program. When an exception occurs an object called exception object is generated, which contains details of exception like name, description, state of program. In this section, we are going to write a java program to handle divide by zero exception and how to handle multiple exceptions. Types of Exceptions− There are three types of exceptions − Checked exception − Checked exceptions are compile time exceptions i.e, they are checked during compilation of program.These cannot be ignored and must be handled by the programmer. ... Read More

Java Program to Extract Digits from A Given Integer

Rushi Javiya
Updated on 31-May-2024 14:02:14

9K+ Views

In Java programming, there are scenarios where we need to extract individual digits from an integer for further manipulation or analysis. This tutorial will guide you through the process of extracting digits from a given integer using Java. Syntax while (num > 0) { int digit = num % 10; System.out.println(digit); num = num / 10; } The above is the syntax to extract digits from an integer in Java. We keep extracting the last digit by taking the remainder of the number with 10. We divide the number by 10 until it ... Read More

Java ResultSet next() method with example

Arushi
Updated on 31-May-2024 13:53:59

21K+ Views

When we execute certain SQL queries (SELECT query in general) they return tabular data.The java.sql.ResultSet interface represents such tabular data returned by the SQL statements.i.e. the ResultSet object holds the tabular data returned by the methods that execute the statements which quires the database (executeQuery() method of the Statement interface in general).The ResultSet object has a cursor/pointer which points to the current row. Initially this cursor is positioned before first row.The next() method of the ResultSet interface moves the pointer of the current (ResultSet) object to the next row, from the current position.Statement stmt = con.createStatement(); ResultSet rs = stmt.executeQuery("Select ... Read More

Java program to convert the contents of a Map to list

Ankith Reddy
Updated on 31-May-2024 13:36:10

27K+ Views

The Map class's object contains key and value pairs. You can convert it into two list objects one which contains key values and the one which contains map values separately. To convert a map to list − Create a Map object. Using the put() method insert elements to it as key, value pairs Create an ArrayList of integer type to hold the keys of the map. In its constructor call the method keySet() of the Map class. Create an ArrayList of String type to hold the values of the map. In ... Read More

Java Program to Display All Prime Numbers from 1 to N

AmitDiwan
Updated on 31-May-2024 13:09:20

29K+ Views

In this article, we will understand how to display all the prime numbers from 1 to N in Java. All possible positive numbers from 1 to infinity are called natural numbers. Prime numbers are special numbers who have only two factors 1 and itself and cannot be divided by any other number.A number is a prime number if its only factors are 1 and itself. 11 is a prime number. Its factors are 1 and 11 itself. Some examples of prime numbers are 2, 3, 5, 7, 11, 13 and so on. 2 is the only even prime number. All ... Read More

Java program to calculate Body Mass Index (BMI)

Samual Sam
Updated on 31-May-2024 13:04:55

21K+ Views

The Body Mass Index is the body mass in kilogram divided by the square of body height in meters. This is expressed as kg/m^2.A Java program that calculates the Body Mass Index (BMI) is given as follows.Exampleimport java.util.Scanner; public class Example {    public static void main(String args[]) {       Scanner sc = new Scanner(System.in);       System.out.print("Input weight in kilogram: ");       double weight = sc.nextDouble();       System.out.print("Input height in meters: ");       double height = sc.nextDouble();       double BMI = weight / (height * height);     ... Read More

Java program to count words in a given string

karthikeya Boyini
Updated on 31-May-2024 12:58:51

13K+ Views

A string is a class in Java that stores a series of characters enclosed within double quotes. Those characters act as String-type objects. The aim of this article is to write Java programs that count words in a given string. Counting words of the given strings can be solved using the string manipulation techniques. In Java interviews, questions from string manipulation are very frequent, hence, it is important to understand this problem properly. Java Program to Count Words in a given String Before jumping to the example programs, let's understand the problem statement with the help of an example. Input ... Read More

What is the Need of Computer Network?

Mr. Satyabrata
Updated on 31-May-2024 12:29:29

8K+ Views

In the modern era, computers have become a vital component of both commercial and private operations in the industry sector. As technological developments have accelerated, networking has become increasingly important. We have gradually transitioned from the first wired network technology to wireless networking technology. If we look at it now, we can see that networking affects everything. A computer network is a collection of interrelated devices that can share resources and exchange data with one another. A network's devices can be physically connected with wires or wirelessly with the help of radio waves or infrared signals. These devices employ a ... Read More

Advertisements