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

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question
100%

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
Transcribed Image Text: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
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
Transcribed Image Text: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
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 4 steps with 2 images

Blurred answer
Knowledge Booster
Developing computer interface
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education