0

Why isn't it working properly????

import java.util.Scanner; public class Main { public static void main(String[] args) { System.out.print("Enter the number:"); Scanner scan = new Scanner(System.in); int result = 0; String giv = scan.nextLine(); String[] arr = giv.split(""); for(String i:arr) { if(i==4) { result++; } System.out.printf("The no of fours is:%d",result); } } }

2nd Feb 2022, 5:57 PM
Ravi King
2 ответов
+ 4
if (i.equals("4")) i is s string so you need to compare it to a string (not an integer)
2nd Feb 2022, 6:19 PM
Lisa
Lisa - avatar
+ 1
Thanks
2nd Feb 2022, 6:19 PM
Ravi King