String Loop method Write a Java program to meet the follow

((String + Loop + method) 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.

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

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

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

You must use below input example (copy and paste) to test your program

Please input a string: y8aM91cA B

ABC123 X

YUM49 YZ

and output should be like:

YUM49 YZ has the maximum number of uppercase: 5

y8aM91cA B has the minimum number of uppercase: 3

Solution

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

public class Solution {

    
    public static void main(String arg[])
    {
        Scanner sc=new Scanner(System.in);
        
        String a=sc.nextLine();
        String b=sc.nextLine();
        String c=sc.nextLine();
        
        int count1,count2,count3;
        Solution s=new Solution();
        
        int max=0;
        int min=0;
        
count1=s.Count_upperCase(a);
        
        count2=s.Count_upperCase(b);
        
        count3=s.Count_upperCase(c);
        
            
        
        
        
        
        
        
        
        if ( count1 > count2 && count1 >count3 )
            System.out.println(a+\" has the maximum number of uppercase:\"+count1);    
        
          else if ( count2 > count1 && count2 > count3 )
            System.out.println(b+\" has the maximum number of uppercase:\"+count2);
          else if ( count3 > count1 && count3 > count2 )
            System.out.println(c+\" has the maximum number of uppercase:\"+count3);    
          else   
             System.out.println(\"Entered numbers are not distinct.\");
        
        
        

        if ( count1 < count2 && count1 <count3 )
            System.out.println(a+\" has the minimum number of uppercase:\"+count1);    
        
          else if ( count2 < count1 && count2 < count3 )
            System.out.println(b+\" has the minimum number of uppercase:\"+count2);
          else if ( count3 < count1 && count3 < count2 )
            System.out.println(c+\" has the minimum number of uppercase:\"+count3);    
          else   
             System.out.println(\"Entered numbers are not distinct.\");
        
        
        
        
        
        
    }
        
    
    int Count_upperCase(String str)
    {
         int count=0;
         int len=str.length();
         
             for(int i=0;i<len;i++)
        {
            if(str.charAt(i)>=65 && str.charAt(i)<92)
            {
                 count++;
            }
               
        }
             return count;
    }
    
    
   }

((String + Loop + method) Write a Java program to meet the following requirements: 1. Prompt the user to enter three strings by using nextline(). Space can be p
((String + Loop + method) Write a Java program to meet the following requirements: 1. Prompt the user to enter three strings by using nextline(). Space can be p

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site