Page 1 of 1

Given a line of text as input, output the number of characters excluding spaces, periods, or commas. Ex: If the input is

Posted: Fri May 20, 2022 6:02 pm
by answerhappygod
Given a line of text as input, output the number of characters
excluding spaces, periods, or commas.
Ex: If the input is:
the output is:
Note: Account for all characters that aren't spaces, periods, or
commas (Ex: "r", "2", "!").
Given A Line Of Text As Input Output The Number Of Characters Excluding Spaces Periods Or Commas Ex If The Input Is 1
Given A Line Of Text As Input Output The Number Of Characters Excluding Spaces Periods Or Commas Ex If The Input Is 1 (62.27 KiB) Viewed 50 times
Given A Line Of Text As Input Output The Number Of Characters Excluding Spaces Periods Or Commas Ex If The Input Is 2
Given A Line Of Text As Input Output The Number Of Characters Excluding Spaces Periods Or Commas Ex If The Input Is 2 (155.65 KiB) Viewed 50 times
Given A Line Of Text As Input Output The Number Of Characters Excluding Spaces Periods Or Commas Ex If The Input Is 3
Given A Line Of Text As Input Output The Number Of Characters Excluding Spaces Periods Or Commas Ex If The Input Is 3 (79.88 KiB) Viewed 50 times
import java.util.Scanner;
public class LabProgram {
public static void main(String[] args) {
Scanner scnr = new Scanner(System.in);
String userText;
int charCount =0;

userText = scnr.nextLine(); // Gets
entire line, including spaces.
for (int i = 0; i < userText.length();
i++){
if (
(userText.charAt(i)>='a'&& userText.charAt(i)<='z')||
(userText.charAt(i)>='A'&&
userText.charAt(i)<='Z'))
{
charCount++;
}
}
System.out.println(charCount);
}
}
I keep missing something
4.15 LAB: Count input length without spa Given a line of text as input, output the number of characters excluding spaces, periods, or commas. Ex: If the input is: Listen, Mr. Jones, calm down. the output is: 21 Note: Account for all characters that aren't spaces, periods, or commas (Ex: "r", "2", "!").

LabPro...m.java Load default template... Nm 0 1 import java.util.Scanner; 2 3 public class LabProgram { 4 public static void main(String[] args) { 5 Scanner scnr = new Scanner(System.in); 6 String userText; 7 int charCount =0; 8 9 userText scnr.nextLine(); // Gets entire line, including spaces. 10 11 12 13 14 15 16 17 18 19 } for (int i = 0; i < userText.length(); i++){ if ( (userText.charAt(i)>='a'&& userText.charAt(i)<='z')|| (userText.charAt(i)>='A'&& userText.charA { charCount++; } } System.out.println(charCount); }

1: Compare output ^ Input Listen, Mr. Jones, calm down. Your output 21 2: Compare output ^ Output differs. See highlights below. Input Howdy! Your output Expected output 6 3: Compare output ^ Input abcd, 1,,efgh....ijkl Your output 12