Java Articles

Page 199 of 450

Java Program to Illustrate String Interpolation

Shriansh Kumar
Shriansh Kumar
Updated on 31-Jul-2024 1K+ Views

String interpolation is a concatenation technique used to display output text dynamically or effectively by replacing the placeholder characters with variables (or strings in the subsequent examples). It restructures the code and prevents the need to repeatedly use variables to produce the output. It makes it efficient to write lengthy variable names or text just by replacing the placeholder with the variable names allocated to strings. String Interpolation in Java There are several ways in Java to perform String Interpolation with the help of the concatenation operator and library function or class. Here, we will discuss four different methods ...

Read More

Java program to print prime numbers below 100

Shriansh Kumar
Shriansh Kumar
Updated on 31-Jul-2024 2K+ Views

Any whole number which is greater than 1 and has only two factors i.e. 1 and the number itself, is called a prime number. Other than these two number it has no positive divisor. In this article, we will explain Java programs to print prime numbers between 1 to 100. Few examples of prime numbers are − 2, 3, 5, 7, 11 etc. Steps to Print Prime numbers below 100 Follow the steps below to print prime numbers below 100 in Java − Take integer variable, let's say "A" Divide the variable A with (A-1 to 2) If A ...

Read More

Java program to print prime numbers below 100

Shriansh Kumar
Shriansh Kumar
Updated on 31-Jul-2024 2K+ Views

Any whole number which is greater than 1 and has only two factors i.e. 1 and the number itself, is called a prime number. Other than these two number it has no positive divisor. In this article, we will explain Java programs to print prime numbers between 1 to 100. Few examples of prime numbers are − 2, 3, 5, 7, 11 etc. Steps to Print Prime numbers below 100 Follow the steps below to print prime numbers below 100 in Java − Take integer variable, let's say "A" Divide the variable A with (A-1 to 2) If A ...

Read More

Java program to swap first and last characters of words in a sentence

AmitDiwan
AmitDiwan
Updated on 31-Jul-2024 3K+ Views

Problem Statement Given a sentence, create a  program in Java that swaps the first and last characters of each word efficiently as given below − Input That is a sample Output The string after swapping the last characters of every word is : thaT si a eampls Steps to swap first and last characters of words in a sentence Below are the steps to swap first and last characters of words in a sentence − Convert string to character array. Iterate through the character array using while loop to identify the ...

Read More

Java program to delete duplicate characters from a given String

karthikeya Boyini
karthikeya Boyini
Updated on 31-Jul-2024 3K+ Views

The Set interface does not allow duplicate elements, therefore, create a set object and try to add each element to it using the add() method in case of repetition of elements this method returns false − If you try to add all the elements of the array to a Set, it accepts only unique elements so, to find duplicate characters in a given string. Problem Statement Given a string, write a program in Java to delete duplicate characters from a given string − Input TUTORIALSPOINT Output Indices of the duplicate characters in the given string :: Index :: ...

Read More

Java program to delete duplicate characters from a given String

karthikeya Boyini
karthikeya Boyini
Updated on 31-Jul-2024 3K+ Views

The Set interface does not allow duplicate elements, therefore, create a set object and try to add each element to it using the add() method in case of repetition of elements this method returns false − If you try to add all the elements of the array to a Set, it accepts only unique elements so, to find duplicate characters in a given string. Problem Statement Given a string, write a program in Java to delete duplicate characters from a given string − Input TUTORIALSPOINT Output Indices of the duplicate characters in the given string :: Index :: ...

Read More

Java Program to Get System IP Address in Windows and Linux Machine

Shiva Keerthi
Shiva Keerthi
Updated on 31-Jul-2024 3K+ Views

IP Address, also known as the Internet Protocol Address is a unique identifier that is assigned to a device in a network to identify the devices in the network and establish a connection between them. In this section, we will learn how to find the IP Address of a Windows and Linux Machine using Java Code. The IP Address can be represented in two formats. One format is IPv4 which is a 32 format containing decimals and dots. It has two parts, one part is network ID which identifies the network and the other is host ID which identifies ...

Read More

Java program to verify whether a given element exists in an array

Maruthi Krishna
Maruthi Krishna
Updated on 31-Jul-2024 1K+ Views

Given an array and one of its element as an input, write a Java program to check whether that element exists in given array or not. You can find any element from an array using search algorithms. In this article, we will use linear search and binary search algorithms. Using Linear Search Algorithm In this approach, follow the steps below to verify whether a given element exists in an array − Iterate through the array using for loop. Compare each element with the required element. If found return the index. Example The following Java program shows how ...

Read More

Java strictfp keyword

Shriansh Kumar
Shriansh Kumar
Updated on 31-Jul-2024 2K+ Views

The strictfp keyword is a modifier that stands for strict floating point. As the name suggests, it ensures that floating-point operations give the same result on any platform. This keyword was introduced in Java version 1.2. In Java, the floating point precision may vary from one platform to another. The strictfp keyword solves this issue and ensures consistency across all platforms. With the release of Java 17 version, the strictfp keyword is no longer needed. Regardless of whether you use this keyword, the JVM now provides consistent results for floating-point calculations across different platforms. When to use Java strictfp keyword? ...

Read More

Java program to Print Odd and Even Number from an Array

Shriansh Kumar
Shriansh Kumar
Updated on 30-Jul-2024 3K+ Views

Given an array of type Integer, write a Java program to find the odd and even numbers from that array. Those numbers which are completely divisible by 2 are called even numbers and if a number gives 1 as a remainder on dividing with 2 is known as odd number. Printing Odd and Even Number from an Array To print odd and even number from an array in Java, use the following ways − Using for Loop Using stream API Using for Loop In this approach, use the for ...

Read More
Showing 1981–1990 of 4,496 articles
« Prev 1 197 198 199 200 201 450 Next »
Advertisements