让用加减法的运算来表示乘除法,我设置的是a=x*y, b=z/w编译出错我也改了改但是还是不通过,请达人帮我看看,谢谢
import java.io.*;
public class Q43
{
     public static void main(String args[])
     {      
           try
           {
              BufferedReader keyboard=new BufferedReader(new InputStreamReader(System.in)); 
 
              int X;
              int y;
              int z;
              int w;
              
              int a=0;
              int b=0;
              int i=0;
              int j=1; 
              System.out.println("X="); 
              System.out.println("y=");
              System.out.println("z=");
              System.out.println("w=");
              X=Integer.parseInt(keyboard.readLine());
              y=Integer.parseInt(keyboard.readLine());
              z=Integer.parseInt(keyboard.readLine());
              w=Integer.parseInt(keyboard.readLine());
              int X=x
              b=z-w;
              if (b==0)
              {
              System.out.print("z divide w is"+b);
              }
                  for (i=1;i<=y;i++)
                  {
                  a=X+a;
                  }
                  System.out.print("multiple of x and y is"+a);
                  while (w!=0 && b!=0)
                  {
                  b=b-w;
                  j=j+1;
                  }
                  System.out.print("z divide w is"+b);
              
            }
           catch(Exception e){}
     }
}

解决方案 »

  1.   

    b=z-w;  ??? 不是 b=z/w 吗?
      

  2.   

    是让用加减法来表示乘除,
    错误是 需要“;”
          b=z-w;不知道是什么意思
      

  3.   

    int   X=x ; // 这里少了分号
      

  4.   

    java2000_net 能帮我改改CODE吗?谢了
      

  5.   

    package test;import java.io.*;public class Q43 {
      public static void main(String args[]) {
        try {
          BufferedReader keyboard = new BufferedReader(new InputStreamReader(System.in));      int x;
          int y;
          int z;
          int w;      int a = 0;
          int b = 0;
          int i = 0;
          int j = 1;
          System.out.println("X=");
          System.out.println("y=");
          System.out.println("z=");
          System.out.println("w=");
          x = Integer.parseInt(keyboard.readLine());
          y = Integer.parseInt(keyboard.readLine());
          z = Integer.parseInt(keyboard.readLine());
          w = Integer.parseInt(keyboard.readLine());      b = z - w;
          if (b == 0) {
            System.out.print("z   divide   w   is" + b);
          }
          for (i = 1; i <= y; i++) {
            a = x + a;
          }
          System.out.print("multiple   of   x   and   y   is" + a);
          while (w != 0 && b != 0) {
            b = b - w;
            j = j + 1;
          }
          System.out.print("z   divide   w   is" + b);    } catch (Exception e) {
        }
      }
    }
      

  6.   

    这个更符合使用习惯
    package test;import java.io.*;public class Q43 {
      public static void main(String args[]) {
        try {
          BufferedReader keyboard = new BufferedReader(new InputStreamReader(System.in));      int x;
          int y;
          int z;
          int w;      int a = 0;
          int b = 0;
          int i = 0;
          int j = 1;
          System.out.print("X=");
          x = Integer.parseInt(keyboard.readLine());
          System.out.print("\ny=");
          y = Integer.parseInt(keyboard.readLine());
          System.out.print("\nz=");
          z = Integer.parseInt(keyboard.readLine());
          System.out.print("\nw=");
          w = Integer.parseInt(keyboard.readLine());      b = z - w;
          if (b == 0) {
            System.out.print("z   divide   w   is" + b);
          }
          for (i = 1; i <= y; i++) {
            a = x + a;
          }
          System.out.print("multiple   of   x   and   y   is" + a);
          while (w != 0 && b != 0) {
            b = b - w;
            j = j + 1;
          }
          System.out.print("z   divide   w   is" + b);    } catch (Exception e) {
        }
      }
    }
      

  7.   

    你明明是 z-w 不是 z/w ,而且你判断
          b = z - w;
          if (b == 0) {只有 z==w 的时候才会运行,因为此时 z-w == 0 , 我看不懂你要干什么!
      

  8.   

    如果你希望得到z/w的结果,应该是如下代码
       // b=z-w;  去掉这一行
          if (w != 0) {
            System.out.println("z   divide   w   is" + b/w); // 防止除0
          }
      

  9.   

    import java.io.*;public class Q43 {
      public static void main(String args[]) {
        try {
          BufferedReader keyboard = new BufferedReader(new InputStreamReader(System.in));      int x;
          int y;
          int z;
          int w;
    String yesOrNo = "y";
    int a=0, b=0;
    while( yesOrNo != null && yesOrNo.startsWith("y" ) ) {
           System.out.print("X=");
           x = Integer.parseInt(keyboard.readLine());
           System.out.print("\ny=");
           y = Integer.parseInt(keyboard.readLine());
           System.out.print("\nz=");
          z = Integer.parseInt(keyboard.readLine());
          System.out.print("\nw=");
           w = Integer.parseInt(keyboard.readLine()); while( w == 0 ) {
    System.out.println( "Divisor cannot be zero!!!!" );
    System.out.print("\nw=");
           w = Integer.parseInt(keyboard.readLine());
    }      for (int i = 0; i < y; i++) {
             a += x;
           }
           System.out.println( String.format(" x*y = %d", a) );
           while ( z >= w) {
             z -= w;
             b++;
           }
           System.out.println( String.format("z/w = %d, remainder = %d", b, z) );
    System.out.println( "Want another try?(y/n)" );
    yesOrNo = keyboard.readLine();
    a = b = 0;
    }

        } catch (Exception e) {
        }
      }
    }