Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a complete program that asks the user to enter a string and then counts th

ID: 3554627 • Letter: W

Question

Write a complete program that asks the user to enter a string and then counts the number of lowercase characters in that string. HINT: Look at the list of methods available under the Character class. Your program should first display the total number of characters in the string, including spaces. Then, on the next line, the number of lowercase characters read.

Here's what I have right now and I can't find out what's wrong with it?

import java.util.Scanner;

public class QuizQuestionII_3 {
  
   public static void main(String [] args) {
  
   Scanner input = new Scanner(System.in);
  
   int count = 0;
  
   System.out.print("Enter a string:");
   String s = input.nextLine();
  
   for (int i = 0; i < s.length(); i++)
       if(Character.isLowerCase(s.charAt(i)) count++;
      
   System.out.println("The total number of characters read was" + s.length() +"including spaces");
  
   System.out.println("The number of lowercase letters in the string was" +count);
  
   }
}

Explanation / Answer

/* package whatever; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
class Ideone
{
   public static void main (String[] args) throws java.lang.Exception
   {
       // your code goes here
       Scanner input = new Scanner(System.in);
  
int count = 0;
  
System.out.print("Enter a string:");
String s = input.nextLine();
  
for (int i = 0; i < s.length(); i++)
if(Character.isLowerCase(s.charAt(i))) count++;
  
System.out.println("The total number of characters read was" + s.length() +"including spaces");
  
System.out.println("The number of lowercase letters in the string was" +count);
   }
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote