Write a program that removes all non alpha characters from the given input. Ex: If the innut is:

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%
There is something wrong with my code It prints more than one line of code help me get my expected output please I’m using Java for this one
LabProgram.java
1 import java.util.Scanner;
e output a
3 public class LabProgram {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
5
differs. See highlights below.
Special character legen
7.
String sentence= sc.nextLine();
String newSentence="";
int character = sentence.length();
9.
Input
-Hello, 1 world$!
10
11
12
for (int i = 0; i < character; i++) {
13
He
14
if (sentence.charAt(i)
'1') {
15
newSentence += "";
16
Hee
17
Hele
18
else if (sentence.charAt(i) ==
19
newSentence += "":
}
} (,$.
Helle
20
21
Helloe
Hello, e
22
else if (sentence.charAt(i) == ' ') {
newSentence += "";
23
24
Hello, e
25
26
Your output
Hello, e
else if (sentence.charAt(i) == '.') {
newSentence += "";
27
28
Hello, e
Hello,we
29
30
else if (sentence.charAt(i) == '@') {
newSentence += "";
31
Hello,wod
32
33
Hello,word
Hello,world
34
else if (sentence.charAt(i) == '-') {
newSentence += "";
35
36
37
Hello,world
38
else if (sentence.charAt(i) == '!') {
39
Hello,worlde
newSentence += "";
}
40
Hello,worlde
41
42
else {
newSentence += sentence.charAt(i);
43
44
pected output
Helloworld
45
46
System.out.println(newSentence);
47
48
49
50
re output a
I
Transcribed Image Text:LabProgram.java 1 import java.util.Scanner; e output a 3 public class LabProgram { public static void main(String[] args) { Scanner sc = new Scanner(System.in); 5 differs. See highlights below. Special character legen 7. String sentence= sc.nextLine(); String newSentence=""; int character = sentence.length(); 9. Input -Hello, 1 world$! 10 11 12 for (int i = 0; i < character; i++) { 13 He 14 if (sentence.charAt(i) '1') { 15 newSentence += ""; 16 Hee 17 Hele 18 else if (sentence.charAt(i) == 19 newSentence += "": } } (,$. Helle 20 21 Helloe Hello, e 22 else if (sentence.charAt(i) == ' ') { newSentence += ""; 23 24 Hello, e 25 26 Your output Hello, e else if (sentence.charAt(i) == '.') { newSentence += ""; 27 28 Hello, e Hello,we 29 30 else if (sentence.charAt(i) == '@') { newSentence += ""; 31 Hello,wod 32 33 Hello,word Hello,world 34 else if (sentence.charAt(i) == '-') { newSentence += ""; 35 36 37 Hello,world 38 else if (sentence.charAt(i) == '!') { 39 Hello,worlde newSentence += ""; } 40 Hello,worlde 41 42 else { newSentence += sentence.charAt(i); 43 44 pected output Helloworld 45 46 System.out.println(newSentence); 47 48 49 50 re output a I
4.20 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
354532.2042412.qx3zgy7
Transcribed Image Text:4.20 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 354532.2042412.qx3zgy7
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 2 images

Blurred answer
Knowledge Booster
Constants and Variables
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