java - Finding the highest and lowest number of lowercase words -


i think i'm close i'm stuck currently. need ask 3 strings , find lower number of lowercase , highest number of lower case input

import java.util.*;  public class practice_program1 {      public static void main(string[] args) {         @suppresswarnings("resource")         scanner input = new scanner(system.in);         int x = 0;         int y = 0;         int z = 0;         string user;         string = input.nextline();         string b = input.nextline();         string c = input.nextline();          (int = 0; < 3; i++) {             system.out.print("enter string: ");             user = input.nextline();              if (character.islowercase(a.charat(i)))                 x++;             else if (character.islowercase(b.charat(i)))                 y++;             else if (character.islowercase(c.charat(i)))                 z++;              {                 if (x > y && x > z)                     ;                 system.out.print(user + " has highest number of lowercase letters" + a);                 if (y > z && y < x)                     ;                 system.out.print(user + " has lowerst number of lowercase letters" + b);              }          }      } } 

well, there few things want point out before providing solution.

  1. i did not understand use of string variable "user". hence, skipped it. if can explain usage, can edit code accordingly, if required.
  2. the condition of 2 strings having same number of lowercase letters not being considered.
  3. the other thing trying count number of lower case letters using iteration variable if strings of 3 different lengths?

that why thought better write separate method count number of lower case letters in each string , comparing count find string maximum lowercase letters , minimum lowercase letters.

public static void main(string[] args) {      scanner input = new scanner(system.in);     string user;     string = input.nextline();     string b = input.nextline();     string c = input.nextline();     input.close();      int countofa = findlowercasenumber(a);     int countofb = findlowercasenumber(b);     int countofc = findlowercasenumber(c);      if(countofa > countofb && countofa > countofc){         system.out.println(a + " has highest number of lowercase letters " + countofa );         if(countofb < countofc)             system.out.println(b + " has lowest number of lowercase letters " + countofb );         else             system.out.println(c + " has lowest number of lowercase letters " + countofc );     }     else if(countofb > countofa && countofb > countofc){         system.out.println(b + " has highest number of lowercase letters " + countofb );         if(countofa < countofc)             system.out.println(a + " has lowest number of lowercase letters " + countofa );         else             system.out.println(c + " has lowest number of lowercase letters " + countofc );     }     else {         system.out.println(c + " has highest number of lowercase letters " + countofc );         if(countofb < countofc)             system.out.println(b + " has lowest number of lowercase letters " + countofb );         else             system.out.println(a + " has lowest number of lowercase letters " + countofa );     } }  public static int findlowercasenumber(string str){     int lowercaseletters = 0;     for(int = 0; < str.length(); i++)         // prefer use ascii values of lower case letters have used correct.         if(str.charat(i) > 96 && str.charat(i) < 123)             lowercaseletters++;     return lowercaseletters; } 

instead of manually comparing count of each string, can use math.max() , math.min() mentioned nullpointer derive solution.


Comments