Write a program that accepts as inputs an asciiz string consisting of a sequence
ID: 670144 • Letter: W
Question
Write a program that accepts as inputs an asciiz string consisting of a sequence of words separated by one or more blanks, and outputs the string with all blanks removed. Example:
input: "the quick brown fox"
output: "thequickbrownfox"
The user should be able to enter any string of maximum length 64 characters after the prompt “Enter the input string:” and the result will be displayed on the screen as “The output string is:”
Please be done in SPIM!. No erros please. In need of a reference.
Explanation / Answer
import java.util.*;
class Rem
{
public static void main(String args[])
{
String str;
Scanner s=new Scanner(System.in);
System.out.println("Enter the string");
str=s.nextLIne();
str whitespaces=str;
System.out.println("Before removing whitespaces:"+str);
str withoutwhitespaces=whitespaces.replaceAll("\s","")
System.out.println("After removing whitespaces:"+without whitespaces);
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.