Write a C programme to check if a number has three consecutive 5s
Answers
Answered by
0
Explanation:
Write a C program to check if a number has three consecutive 5s. If yes, print YES, else print NO.
Example:
Number: 1353554
Result: NO
Number: 345559
Result: YES
Answered by
0
Answer:
public class Main
{
public static void main(String[] args) {
java.util.Scanner sc = new java.util.Scanner(System.in);
System.out.print("Enter a number:");
int num = sc.nextInt();
for(int i = 0; i < num.length(); i++){
if(num.charAt(i) == '5' && num.charAt(i+1)== '5' && num.charAt(i+2)== '5'){
System.out.println("YES");
}
else{
System.out.println("NO");
}
}
}
}
Explanation:
Similar questions