+ 6
Java String
Why does when i put the word BananA it only counts the first uppercase when it should count also the last Uppercase? just like when i try to input A-a, the answer is uppercase: 0 and lowercase: 0, the count of the letters are also wrong, in BananA word the count is uppercase: 1, lowercase: 2, can someone help me on this? thanks! ❤️ https://code.sololearn.com/cgU6bHqx6T0a/?ref=app
6 odpowiedzi
+ 2
Try now u missed = sign in conditions that's why try now its working
import java.util.Scanner;
public class Program
{
public static void main(String[] args)
{
Scanner user = new Scanner(System.in);
System.out.println("Enter a String:\n");
String str = user.nextLine();
int a=0, b=0;
for(int i=0;i<str.length();i++)
{
if(str.charAt(i)>='A'&& str.charAt(i)<='Z')
{
a++;
}
else if(str.charAt(i)>='a'&& str.charAt(i)<='z')
{
b++;
}
}
System.out.println("Upper Case Letters : "+a);
System.out.println("Lower Case Letters : "+b);
}
}
+ 3
Ab Rahman Bahadori why you posting unnecessary comment
+ 3
Ab Rahman Bahadori ohh then great
+ 2
Thank you! ♨️♨️
+ 1
Because my problem is solved
0
Thanks