+ 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

15th Oct 2020, 3:13 AM
Lia Costa ✨
Lia Costa ✨ - avatar
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); } }
15th Oct 2020, 3:40 AM
A S Raghuvanshi
A S Raghuvanshi - avatar
+ 3
Ab Rahman Bahadori why you posting unnecessary comment
15th Oct 2020, 6:31 AM
A S Raghuvanshi
A S Raghuvanshi - avatar
+ 3
Ab Rahman Bahadori ohh then great
15th Oct 2020, 6:35 AM
A S Raghuvanshi
A S Raghuvanshi - avatar
+ 2
Thank you! ♨️♨️
15th Oct 2020, 3:43 AM
Lia Costa ✨
Lia Costa ✨ - avatar
+ 1
Because my problem is solved
15th Oct 2020, 6:34 AM
Ab Rahman Bahadori
Ab Rahman Bahadori - avatar
0
Thanks
15th Oct 2020, 6:24 AM
Ab Rahman Bahadori
Ab Rahman Bahadori - avatar