remove extra blank spaces from string in java
Java
import java.util.Scanner;
class RemoveExtraSpace{ //starting of class
public static void main(String[] args){ //starting of the main function
Scanner sc=new Scanner(System.in); //declaring an object of the Scanner class
String input,output="";
char c;
int i,len;
System.out.println("ENTER A SENTENCE.");
input=sc.nextLine().trim(); //accepting the input
len=input.length();
for(i=0;i<len;i++){ //outer for loop to traverse each character
c=input.charAt(i);
output+=c;
if(c==' '){
while(input.charAt(i)==' '){ //inner while loop to skip through repeated spaces
i++;
} //end of while loop
i--; //decrementing i by 1 so that the immediate character after space is taken
}
} //end of for loop
System.out.println(output); //printing the result
} //closing of main function
} //closing of class
Also in Java:
- Title
- creating a program about user asked to enter a number and enters 0 to stop, then calculates the sum of numbers entered, the average, the length of positive numbers and negative numbers entered by the user in java
- Category
- Java
- Title
- java clear bufffer to take next string inpuit
- Category
- Java
- Title
- padding a string with 0 in java
- Category
- Java
- Title
- parse string to int java
- Category
- Java
- Title
- what is graphics default color java
- Category
- Java
- Title
- instantiate optinal java 8
- Category
- Java
- Title
- jackson ignore values if empty
- Category
- Java
- Title
- .length array java
- Category
- Java
- Title
- processing string to int
- Category
- Java
- Title
- java list to set
- Category
- Java
- Title
- ternary operator java
- Category
- Java
- Title
- how to make a pre set list java
- Category
- Java
- Title
- java hashmap set value
- Category
- Java
- Title
- string equality in java
- Category
- Java
- Title
- send variable intent
- Category
- Java
- Title
- how to multiply a number by itself using for loop in java
- Category
- Java
- Title
- print in one line in java
- Category
- Java
- Title
- how to init an array with objects in java
- Category
- Java
- Title
- java sql question mark
- Category
- Java
- Title
- java get current milliseconds
- Category
- Java
- Title
- java catch multiple exceptions
- Category
- Java
- Title
- java regex replace all characters before
- Category
- Java
- Title
- public static void main(string args)
- Category
- Java
- Title
- how to add objects in array java
- Category
- Java
- Title
- java double 2 decimal
- Category
- Java
- Title
- java calculator code
- Category
- Java
- Title
- int java
- Category
- Java
- Title
- index 1 out of bound for length 1 java
- Category
- Java
- Title
- how to change top of window in java
- Category
- Java
- Title
- how to use the this keyword in java
- Category
- Java
- Title
- java load image
- Category
- Java
- Title
- double to string java
- Category
- Java
- Title
- math minimum java
- Category
- Java
- Title
- how to change the color of a menubar in java
- Category
- Java
- Title
- list in java
- Category
- Java
- Title
- how to make a char uppercase in java
- Category
- Java
- Title
- abstraction in java
- Category
- Java
- Title
- eclipse does not support logback with spring boot
- Category
- Java
- Title
- how to append to a string in java
- Category
- Java
- Title
- String array into LinkedList java
- Category
- Java
- Title
- import classes from another project java
- Category
- Java
- Title
- onbackpressed android
- Category
- Java
- Title
- recursive function for fibonacci series in java javascript
- Category
- Java
- Title
- dates in java 8
- Category
- Java
- Title
- spigot get player from UUID
- Category
- Java
- Title
- guess the number java
- Category
- Java
- Title
- scanner in java
- Category
- Java
- Title
- int to binary string java
- Category
- Java
- Title
- java get excectuon time
- Category
- Java
- Title
- java quit application
- Category
- Java
- Title
- java convert a set to array
- Category
- Java
- Title
- how to find complement of a number in java
- Category
- Java
- Title
- java valeur absolue
- Category
- Java
- Title
- initialize arraylist
- Category
- Java
- Title
- recursion in java
- Category
- Java
- Title
- how to create array of linkedlist in java
- Category
- Java
- Title
- transformer un string en double java
- Category
- Java
- Title
- throwing exceptions java
- Category
- Java
- Title
- capitalize string java
- Category
- Java
- Title
- Java system load from resources
- Category
- Java
- Title
- java get command line input
- Category
- Java
- Title
- how to create a 2d arraylist java
- Category
- Java
- Title
- java resultset to table
- Category
- Java
- Title
- java pass array as method parameter
- Category
- Java
- Title
- how to import an arraylist in java
- Category
- Java
- Title
- 2d array java
- Category
- Java
- Title
- kotlin jsonobject get nested
- Category
- Java
- Title
- java stream sort Collator
- Category
- Java
- Title
- how to reverse a string in java
- Category
- Java
- Title
- serialversionuid java
- Category
- Java
- Title
- java string to double
- Category
- Java
- Title
- java random number generator in range
- Category
- Java
- Title
- java array to list
- Category
- Java
- Title
- how to declare an array in java
- Category
- Java
- Title
- boolean java.lang.String.equals(java.lang.Object)' on a null object reference
- Category
- Java
- Title
- how to send http post create request using curl command
- Category
- Java
- Title
- java string split underscore
- Category
- Java
- Title
- how to create gravity in java
- Category
- Java
- Title
- java sort method
- Category
- Java
- Title
- java literals w3schools
- Category
- Java
- Title
- string to char in java
- Category
- Java
- Title
- validate isbn number java
- Category
- Java
- Title
- java sleep in code
- Category
- Java
- Title
- how to iterate hashmap java
- Category
- Java
- Title
- change the value in a hashtable java
- Category
- Java
- Title
- socket programming in java
- Category
- Java
- Title
- most common element in list java
- Category
- Java
- Title
- how to find the total of the products added to the shopping cart in java program
- Category
- Java
- Title
- mkyong restful web services spring boot examples post
- Category
- Java
- Title
- android dynamically create layer-list with item and shape site:stackoverflow.com
- Category
- Java
- Title
- Primitive Type vs. Reference Type
- Category
- Java
- Title
- what is a variable in java
- Category
- Java
- Title
- string contains java
- Category
- Java
- Title
- converter int array para string java
- Category
- Java
- Title
- how to remove duplicates from an array java
- Category
- Java
- Title
- java shortest if else statement
- Category
- Java
- Title
- java swing button on click
- Category
- Java
- Title
- spigot kill entity
- Category
- Java
- Title
- how to split a string in java
- Category
- Java
- Title
- how to remove all special characters from a string in java
- Category
- Java