6.21 LAB: Remove all non alpha characters Write a program that removes all non alpha characters from the given input. Ex: If the input is: -Hello, 1 world$! the output is: Helloworld 296430.1461558.qx3zqy7 LAB 6.21.1: LAB: Remove all non alpha characters 2/ 10 АCTIVITY
I'm unable to use the method replaceAll because we have not touch upon it yet, so since the chapter cover loops, here are my 2 codes
(Code 1)
import java.util.Scanner;
public class LabProgram {
public static void main(String[] args) {
/* Type your code here. */Scanner scnr = new Scanner(System.in);
String str= scnr.next();
String newStr="";
for (int i=0; i < str.length(); i++) {
if (str.charAt(i) == '@')
newStr+="";
else if (str.charAt(i) == '1')
newStr+="";
else if (str.charAt(i) == '!')
newStr+="";
else if (str.charAt(i) == '-')
newStr+="";
else if (str.charAt(i) == '$')
newStr+="";
else if (str.charAt(i) == '.')
newStr+="";
else if (str.charAt(i) == ' ')
newStr+="";
else
newStr= str.charAt(i);
}
System.out.println(newStr);
}
}
(Code 2)
It's the same as the 1st code but I removed the charAt(i) to newStr as in:
newStr=str;
System.out.println(newStr);
This code displayed the string but no nonalpha characters were removed.
![uDiit T mode
submit your program for auto-grading.
Submit for grading
Signature of your work
What is this?
3/7.. U|2|2 |2|2|0|0|0| 0|2|0 ..3/7
Latest submission - 8:04 PM PST on 03/07/21
Total s
Download this
Failed to compile
LabProgram.java:25: error: incompatible types: char cannot be converted to String
newStr= str.charAt(i);
1 error](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2Fc14768d3-3359-407d-85b4-624ecac227c9%2Fc9749e8b-0883-4b4c-81f7-8c259c56b3f0%2F6rkd7jm_processed.png&w=3840&q=75)
![6.21 LAB: Remove all non alpha characters
Write a program that removes all non alpha characters from the given input.
Ex: If the input is:
-Hello, 1 world$!
the output is:
Helloworld
296430.1461558.qx3zqy7
LAB
6.21.1: LAB: Remove all non alpha characters
2/10
ACTIVITY](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2Fc14768d3-3359-407d-85b4-624ecac227c9%2Fc9749e8b-0883-4b4c-81f7-8c259c56b3f0%2F5ygtjq_processed.png&w=3840&q=75)
![](/static/compass_v2/shared-icons/check-mark.png)
Trending now
This is a popular solution!
Step by step
Solved in 4 steps with 2 images
![Blurred answer](/static/compass_v2/solution-images/blurred-answer.jpg)
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
![C How to Program (8th Edition)](https://www.bartleby.com/isbn_cover_images/9780133976892/9780133976892_smallCoverImage.gif)
![Database Systems: Design, Implementation, & Manag…](https://www.bartleby.com/isbn_cover_images/9781337627900/9781337627900_smallCoverImage.gif)
![Programmable Logic Controllers](https://www.bartleby.com/isbn_cover_images/9780073373843/9780073373843_smallCoverImage.gif)