Print Multiplication Table for Any Number in Java

Shriansh Kumar
Updated on 01-Aug-2024 10:58:04

2K+ Views

For a given integer number, write a Java program to print its multiplication table. In mathematics, a multiplication table shows the product of two numbers. Printing Multiplication Table using for Loop In Java, a for loop is used when a specific block of code needs to be executed multiple times. Here, we will run this loop 10 times and increment the loop variable by one with each iteration. During this iteration, multiply the given integer value with the current value of the loop variable to get the multiplication table. Example Following is a Java program which prints the multiplication ... Read More

Convert Octal to Binary in Java

Shriansh Kumar
Updated on 01-Aug-2024 10:56:06

1K+ Views

Both binary and octal are types of number systems with the base value 2 and 8, respectively. This article aims to explain how to convert octal to binary in Java, which is one of the frequently asked interview questions. A number system is a way of representing numbers. Each type of number system has a different base value which depends on the number of digits contained by them. What is Binary Number System? There are four types of number systems available. Binary numbers are one of them. It is represented with two digits i.e. one (1) and zero (0). The ... Read More

Java Program for Case Specific Sorting

Shriansh Kumar
Updated on 01-Aug-2024 10:49:54

828 Views

Suppose you have a String that contains uppercase and lowercase characters both. We have to sort this given string in case specific order which means if the ith position in the given string had an uppercase letter then the newly sorted string must have uppercase letter at that position and same goes for lowercase letters. Also, both lowercase and uppercase letters will be in sorted order separately. In this article, we will try to find the solution for the given problem. First, let's understand the given problem with an example for better understanding. Example Scenario Input: String st = ... Read More

Find All Duplicate Characters in a String in Java

Shriansh Kumar
Updated on 01-Aug-2024 10:46:49

66K+ Views

The duplicate characters in a string are those that occur more than once. In Java, String is a non-primitive datatype that contains one or more characters and is enclosed in double quotes(“ ”). As per the problem statement, we are given a string and our task is to write a Java program to find all the duplicate characters from that string. We can use for loop and nested for loop to solve this given problem. Example Scenario Input: String str = "Apple"; Output: duplicate_char = p; p is a duplicate character as it occurs more than once. Using ... Read More

Compare Two Objects in Java

Shriansh Kumar
Updated on 31-Jul-2024 19:55:42

1K+ Views

To compare objects in Java, check the properties or the hash value of given objects. If the properties of both objects matches, then they are equal. If either property is different, it indicate that the objects are not equal. NOTE: Don't use equality operator (==) to compare objects as it checks only their memory location. Objects comparison should be done based on the properties not location. How to Compare Objects in Java? To compare two objects in Java, use the following approaches − By overriding equals() method Without overriding equals() method ... Read More

Find Frequency of a Character in a Given String in Java

Shriansh Kumar
Updated on 31-Jul-2024 19:54:06

7K+ Views

For a given a string, write a Java program to find the frequency of a particular character. In Java, String is a datatype that contains one or more characters and is enclosed in double quotes(“ ”). Finding Frequency of a Character in a String To find the Frequency of a character in a given String, follow the below ways − Using for Loop Using Stream API Using for loop In this approach, use the for loop to compare each character in the given string with the character whose ... Read More

String Interpolation in Java

Shriansh Kumar
Updated on 31-Jul-2024 19:53:44

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

Print Prime Numbers Below 100 in Java

Shriansh Kumar
Updated on 31-Jul-2024 19:53:03

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

Swap First and Last Characters of Words in a Sentence in Java

AmitDiwan
Updated on 31-Jul-2024 17:51:50

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

Remove Items from Set in Java

karthikeya Boyini
Updated on 31-Jul-2024 17:51:18

4K+ Views

A set in Java is modelled after the mathematical set and it cannot contain duplicate elements. The set interface contains the methods that are inherited from Collection. The method remove() removes the specified items from the set collection. A program that demonstrates the removal of items from Set using remove() is given as follows − Problem Statement Given a Set, write a Java program to remove the elements from the Set − Input [115, 20, 5, 70, 89, 10, 30, 111] Output [115, 20, 5, 70, 10, 30, 111] ... Read More

Advertisements