如果不采用用户输入的方法的话,那就采用给xy赋初值的简单办法。
这个没什么好写的,上面的公式又不用计算,直接输出,这只是让你判断xy是否为整数的程式。
你先给xy赋个初值,写个判断 xy 是否%2为0
----------------解决方案--------------------------------------------------------
我觉得是不是可以使用随机数?
----------------解决方案--------------------------------------------------------
这种题目方法有很多,可以随机,输入
----------------解决方案--------------------------------------------------------
%2为0,那不是变成判断偶数啦~~~
----------------解决方案--------------------------------------------------------
哦,那就改为判断是不是大于0嘛
----------------解决方案--------------------------------------------------------
----------------解决方案--------------------------------------------------------
这个没什么好写的,上面的公式又不用计算,直接输出,这只是让你判断xy是否为整数的程式。
你先给xy赋个初值,写个判断 xy 是否%2为0
程序代码:
public class Zhengming
{
public static void main(String args[])
{
int x=20,y=41;//给xy赋初值
boolean zhengming=true;
if(x%2==0 && y%2==0)
zhengming=true;
else
zhengming=false;
System.out.println("x=(x/y)*y+x%y is "+zhengming);
}
}
{
public static void main(String args[])
{
int x=20,y=41;//给xy赋初值
boolean zhengming=true;
if(x%2==0 && y%2==0)
zhengming=true;
else
zhengming=false;
System.out.println("x=(x/y)*y+x%y is "+zhengming);
}
}
----------------解决方案--------------------------------------------------------
我觉得是不是可以使用随机数?
----------------解决方案--------------------------------------------------------
这种题目方法有很多,可以随机,输入
----------------解决方案--------------------------------------------------------
%2为0,那不是变成判断偶数啦~~~
----------------解决方案--------------------------------------------------------
哦,那就改为判断是不是大于0嘛
----------------解决方案--------------------------------------------------------
程序代码:
import java.util.*;
public class Test
{
public static void main(String[] args)
{
int x, y;
Random rand = new Random();
boolean operator = rand.nextInt(100)%2 == 0;
if(operator)
x = rand.nextInt(100);
else
x = -rand.nextInt(100);
operator = rand.nextInt(100)%2 == 0;
if(operator)
y = rand.nextInt(100);
else
y = -rand.nextInt(100);
System.out.println("x = " + x + " y = "+ y);
if(y != 0 && x == (x/y)*y+x%y)
System.out.println("如果x和y都是整数且y != 0,则x=(x/y)*y+x%y成立");
else
System.out.println("如果x和y不都是整数或y == 0,则x=(x/y)*y+x%y不成立");
}
}
public class Test
{
public static void main(String[] args)
{
int x, y;
Random rand = new Random();
boolean operator = rand.nextInt(100)%2 == 0;
if(operator)
x = rand.nextInt(100);
else
x = -rand.nextInt(100);
operator = rand.nextInt(100)%2 == 0;
if(operator)
y = rand.nextInt(100);
else
y = -rand.nextInt(100);
System.out.println("x = " + x + " y = "+ y);
if(y != 0 && x == (x/y)*y+x%y)
System.out.println("如果x和y都是整数且y != 0,则x=(x/y)*y+x%y成立");
else
System.out.println("如果x和y不都是整数或y == 0,则x=(x/y)*y+x%y不成立");
}
}
----------------解决方案--------------------------------------------------------