让用加减法的运算来表示乘除法,我设置的是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){}
}
}
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){}
}
}
错误是 需要“;”
b=z-w;不知道是什么意思
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) {
}
}
}
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) {
}
}
}
b = z - w;
if (b == 0) {只有 z==w 的时候才会运行,因为此时 z-w == 0 , 我看不懂你要干什么!
// b=z-w; 去掉这一行
if (w != 0) {
System.out.println("z divide w is" + b/w); // 防止除0
}
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) {
}
}
}