package com.company;
import java.io.IOException;
import java.util.Scanner;
public class Favorite_Number {
public static void main(String[] args) throws IOException {
//write your code here
int X,sum = 0,rem = 0,t;
Scanner s = new Scanner(System.in);
t = s.nextInt();
while(t!=0) {
s.reset(); what does it do if i remove also the program works fine
X = s.nextInt();
/while (X > 0) {
rem = X % 10;
if (rem == 5) {
sum ;
}
X = X / 10;
}
System.out.println(sum);
sum = 0;
t--;
}
}
}
s.reset(); what does it do if i remove also the program works fine
CodePudding user response:
reset is explained here with examples
https://www.geeksforgeeks.org/scanner-reset-method-in-java-with-examples/?tab=article
and as per documents purpose stated as... Resetting a scanner discards all of its explicit state information which may have been changed by invocations of useDelimiter(java.util.regex.Pattern), useLocale(java.util.Locale), or useRadix(int).
doc ref: https://docs.oracle.com/javase/7/docs/api/java/util/Scanner.html#reset()