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); } } }
2 Respuestas
+ 4
if (i.equals("4"))
i is s string so you need to compare it to a string (not an integer)
+ 1
Thanks