Java Program to remove all the white spaces from a string8 Jan 2025 | 1 min read In this program, our task is to remove all the white-spaces from the string. For this purpose, we need to traverse the string and check if any character of the string is matched with a white-space character or not. If so, use any built-in method like replace() with a blank. In C, we do not have any built-in method to replace. Therefore, we need to run for loop to traverse the string and see if there is any white-space character or not. If so, then start the inner loop (j) from ith character to len and keep replacing each element with its next adjacent element. Decrease the length of the string by 1 on the termination of this loop. Repeat this process until all the white-spaces of the string are removed. The algorithm of the program is given below. Algorithm
Program:Output: String after removing all the white spaces: Removewhitespaces Next TopicJava Programs |
Java program to print the following pattern Algorithm: STEP 1: START STEP 2: SET i=1,j=1,k=1,l=1,direction=1 STEP 3: SET matrix[5][5] STEP 4: REPEAT STEP 5 to 9 UNTIL i is less than 5 STEP 5: SET j=0 STEP 6: REPEAT STEP 7 and 8 UNTIL j is less than 5 STEP 7: SET matrix[i][j]=0 STEP...
11 min read
In this section, we will learn how to reverse a number in Java using while loop, for loop and recursion. To reverse a number, follow the steps given below: First, we find the remainder of the given number by using the modulo (%) operator. Multiply the variable reverse...
5 min read
Java Convert int to String We can convert int to String in java using String.valueOf() and Integer.toString() methods. Alternatively, we can use String.format() method, string concatenation operator etc. Scenario It is generally used if we have to display number in textfield because everything is displayed as a string in...
2 min read
It is very interesting problem frequently asked in interviews of top IT companies like Google, Amazon, TCS, Accenture, etc. By solving the problem, one wants to check the logical ability, critical thinking, and problem-solving skill of the interviewee. So, in this section, we are going...
6 min read
In this program, we will create a singly linked list and add a new node at the middle of the list. To accomplish this task, we will calculate the size of the list and divide it by 2 to get the mid-point of the list...
7 min read
Java pattern program enhances the coding skill, logic, and looping concepts. It is mostly asked in Java interview to check the logic and thinking of the programmer. We can print a Java pattern program in different designs. To learn the pattern program, we must have...
15 min read
The spiral pattern (or matrix in spiral form) is frequently asked in Java interviews and academics. In this section, we will create a Java program to create a spiral pattern or spiral matrix. What is Spiral Matrix or Spiral Pattern? A spiral pattern is a number pattern...
7 min read
Seven segments display is an output display device. It provides a way to display information in the form of images, text, or decimal numbers. It is an alternative to complex dot matrix displays. Seven segment displays are widely used in digital or electronic devices like calculators,...
8 min read
In this program, we need to calculate the sum of elements in each row and each column of the given matrix. Above diagram shows the sum of elements of each row and each column of a matrix. Algorithm STEP 1: START STEP 2: DEFINE rows, cols, sumRow, sumCol STEP 3:...
3 min read
ASCII acronym for American Standard Code for Information Interchange. It is a 7-bit character set contains 128 (0 to 127) characters. It represents the numerical value of a character. For example, the ASCII value of A is 65. In this section, we will learn how to print...
3 min read
We request you to subscribe our newsletter for upcoming updates.
We provides tutorials and interview questions of all technology like java tutorial, android, java frameworks
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India