import java.util.Scanner;
public class remainder
{
public static void main(String args[])
{
Scanner input=new Scanner(System.in);

int a;
int b;
 
    a=input.nextInt();
    
    
    b=input.nextInt();
    
   
    
   if(a%b!=0)      System.out.printf("the first isn's a multiple of the second.");
    else
     System.out.printf("the first is a multiple of the second.");
    
  
}
} 主要程序是这样的`最后结果都是the first is a multiple of the second.无论输入什么数字`我很郁闷的啊`
然后用import java.util.Scanner;
public class remainder
{
public static void main(String args[])
{
Scanner input=new Scanner(System.in);

int a;
int b;
 
 System.out.printf("the first:");
    a=input.nextInt();
    
    System.out.printf("the second:");
    b=input.nextInt();
    
   
    
   if(a%b!=0)      System.out.printf("the first isn's a multiple of the second.");
    else
     System.out.printf("the first is a multiple of the second.");
    
  
}
} 就又成功了 `这个就更刺激我了`前辈们`给点理论知识`我我不太懂了`

解决方案 »

  1.   

    可以在执行a%b之前,把a,b的值输出来就能看出问题了
      

  2.   

    不是求余出的问题,是输入缓存的影响!改用如下方法输入会比较安全:
    Scanner input = new Scanner(System.in);
    int a = 0;  //给变量赋初值
    int b = 0;  //可避免很多问题
    System.out.print("Please input the first number: ");
    try {
        a = Integer.parseInt(input.nextLine());
    } catch (Exception e) {
        System.out.println("Input error !");
    }
    System.out.print("Please input the second number: ");
    try {
        b = Integer.parseInt(input.nextLine());
    } catch (Exception e) {
        System.out.println("Input error !");
    }
    System.out.println("a = " + a);  //用于验证输入的值到底是什么
    System.out.println("b = " + b);  //和上一语句都属调试性代码
      

  3.   

    我测试出来了 ·结果是:最后B的值等于A的 值。
    不管我B输入什么值·都是等于A的值!·
      

  4.   

    所谓输入缓存原理如下:
    首先要清楚一点,我们在控制台也就是CMD窗口中输入的只是字符序列,Scanner的功能是根据分割符(通常是空白符例如空格、制表符Tab、回车换行符等的序列)自动完成输入字符中词的分割,每两个空白符序列之间的字符会被认为是一个词,而nextInt的作用是将下一个的词解析为整数返回。
    输入缓存(或称为缓冲区)的作用类似水库,存的是字符而已。当nextInt方法被调用时,首先它检测缓冲区是否为空,如果不为空则根本不会出现闪动的光标提示输入,而是直接从缓冲区中读出下一个词,并将其从缓冲区中删除,然后作解析并返回解析出的整数。
    当然刚刚初始化好的Scanner的缓冲区是空的,这时当nextInt(或其它nextXXX方法)被调用时,由于缓冲区是空的没有字符可读,所以程序暂停执行(更准确的叫法是main线程被阻塞)出现闪动的光标,这时我们就可以输入字符了。输入的字符会自动存入上面提到的缓冲区,当我们键入回车时,暂停执行的程序会恢复执行,下面所做的事儿和上面相同,即:从缓冲区中读出下一个词,并将其从缓冲区中删除,然后作解析并返回解析出的整数。
    原理如上,仔细分析一下你会发现问题出在哪儿的。
      

  5.   

    LZ给的两段程序都没有什么问题啊
     只是第二段在从键盘捕获 int 型的 a 和 b 的值的时候多了两句提示用的语句而已如果你输入的a和b的值一样 余数肯定是0啊 是不是你自己输入的过程中有笔误啊