通过Scanner类里的hasNext()实现。以下是Example:
import java.util.Scanner;;
public class Main
{
public static void main(String[] args)
{
Scanner cin = new Scanner(System.in);
int a, b;
while (cin.hasNext())
{
a = cin.nextInt();
b = cin.nextInt();
System.out.println(a % b);
}
}
}
/**************************************************************************
                 
原文来自博客园——Submarinex的博客: www.cnblogs.com/submarinex/               
 
*************************************************************************/