Question

Write a Java program to meet the following requirements: 1. Prompt the user to enter three...

Write a Java program to meet the following requirements:

1. Prompt the user to enter three strings by using nextLine(). Space can be part of the string). ( Note: your program requires using loop: for-loop, while-loop or do-while-loop to get the input String )

2. Write a method with an input variable (string type).The method should return the number of lowercase letters of the input variable.

3. Get the number of the lowercase letters for each user input string by calling the method.

4. Compare the lowercase numbers and display the maximum, minimum lowercase numbers and the strings

5. You need to have proper comments.

6. You must use below testing data (copy and paste) to test your program.

Test input number: 12345

Check INPUT String: abc

MAXIMUM number

0 0
Add a comment Improve this question Transcribed image text
Answer #1

import java.util.*;
public class Main
{
//2
//method to find number of lower case letters in given input variable
static int count_lowercase(String x)
{
int c=0;
for(int i=0;i<x.length();i++)
{
char d= x.charAt(i);//getting each char in x
if(97<=d && d<123)//if it is lowercase then
c++;//increasing count
}
return c;//returning count
  
}
   public static void main(String[] args) {
  
   //1  
       Scanner sc = new Scanner(System.in);//to read input
      
       System.out.println("Enter 3 strings in each line:");
       String s[]=new String[3];
       for(int i=0;i<3;i++)
       s[i]=sc.nextLine();//reading strings
      
       int max,min,maxc,minc;//declaring required variables
       max=min=0;
       int c=count_lowercase(s[0]);//calling method for string1
       int c2=count_lowercase(s[1]);//calling method for string2
       if(c<c2)//finding min and max string with lower case letters
       {max=1;
       maxc=c2;
       minc=c;
      
       }else
       {max=0;
       maxc=c;
       minc=c2;
   }
       c2=count_lowercase(s[2]);//calling method for string3
       if(maxc<c2)//finding min and max string with lower case letters
       {max=2;
       maxc=c2;
       }
       else if(c2<minc)
       {
       minc=c2;
       min=2;
       }
      
       //now displaying output
       System.out.println("String with max lower case letters :"+s[max]+" count:"+maxc);
       System.out.println("String with min lower case letters :"+s[min]+" count:"+minc);
   }
}

output:

Enter 3 strings in each line:
Hi
Hello
How are you
String with max lower case letters :How are you count:8
String with min lower case letters :Hi count:1

Add a comment
Know the answer?
Add Answer to:
Write a Java program to meet the following requirements: 1. Prompt the user to enter three...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Ask uFor Ex. "Prompt user to enter a number" = user enters 10, your program should...

    Ask uFor Ex. "Prompt user to enter a number" = user enters 10, your program should output 1, 2, 3, 4, 5, 6, 7, 8, 9, 10.ser to input a number, and then using a loop control statement (While, For, Do-While), output to the console the numbers beginning from 1, up to and including the number input by the user.

  • Write a program that will loop ten times. In each iteration prompt user to enter an...

    Write a program that will loop ten times. In each iteration prompt user to enter an integer between -50&50. Print the input, keep a running sum of the inputs, and track the minimun and maximum numbers input. After the loop is complete, minimum number entered, maximum number entered, sum of all numberes entered, and average of all numbers entered. Format all output. Before running the loop, print the label "Input values: ". Within the loop, print value entered by user...

  • Prompt the user to enter two character strings. The program will then create a new string...

    Prompt the user to enter two character strings. The program will then create a new string which has the string that appears second, alphabetically, appended to the end of the string that shows up first alphabetically. Use a dash (-') to separate the two strings. You must implement the function string appendStrings(string, string), where the return value is the combined string. Display the newly created string. Your program must be able to handle both uppercase and lowercase characters. You are...

  • Write a Java program to prompt for inputting an integer N, then enter N integers (a...

    Write a Java program to prompt for inputting an integer N, then enter N integers (a loop is needed), print the numbers user entered, and the amount of even and odd numbers (zero is even number). (1) Prompt for the user to input an integer and output the integer. (1 pts) Enter an integer: You entered: 5 (2) Prompt for the user to input N integers, output the numbers entered and the amount of even and odd numbers (9 pts)...

  • In the first task, you will write a Java program that accepts a string of the...

    In the first task, you will write a Java program that accepts a string of the format specified next and calculate the answer based on the user input. The input string should be of the format dddxxdddxx*, where d represents a digit and x represents any character and asterisk at the end represents that the string can have any number of characters at the end. 1. Prompt the user to enter a string with the specific format (dddxxdddxx*) 2. Read...

  • C++ Program Write a do-while loop that continues to prompt a user to enter a number...

    C++ Program Write a do-while loop that continues to prompt a user to enter a number less than 100, until the entered number is actually less than 100. End each prompt with a newline. Ex: For the user input 123, 395, 25, the expected output is: Enter a number (<100): Enter a number (<100): Enter a number (<100): Your number < 100 is: 25 #include <iostream> using namespace std; int main() { int userInput; /* Your solution goes here */...

  • Write a C program that prompts the user for an input string with all lowercase letters....

    Write a C program that prompts the user for an input string with all lowercase letters. Your program should then sort the characters in the string and print the sorted string. Assume that the string contains no spaces and has at most 30 lowercase characters. Your program should loop continually until the user enters “q” to quit.

  • In java, write a program that gets 10 integer numbers from the user using user input,...

    In java, write a program that gets 10 integer numbers from the user using user input, and then calculates and display the sum of the numbers that have been read.   Program Requirements: Write the program in three versions with three loops. Put all three loops in the main method of your source code. version1:  use a while loop. version2:  use a do-while loop. version 3:  use a for loop. For each version, use a loop to input 10 int numbers from the user...

  • Write a program to prompt the user for hours and rate per hour using input to...

    Write a program to prompt the user for hours and rate per hour using input to compute gross pay. Pay should be the normal rate for hours up to 40 and time-and-a-half for the hourly rate for all hours worked above 40 hours. Put the logic to do the computation of pay in a function called computepay() and use the function to do the computation. The function should return a value. Use 45 hours and a rate of 10.50 per...

  • In java, write a program that gets 10 integer numbers from the user using user input,...

    In java, write a program that gets 10 integer numbers from the user using user input, and then calculates and display the sum of the numbers that have been read.   Program Requirements: Write the program in three versions with three loops. Put all three loops in the main method of your source code. The program must be in one file. version1:  use a while loop. version2:  use a do-while loop. version 3:  use a for loop. For each version, use a loop to...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT