我试图使用DeMorgan定律简化以下内容:(x!= 0 || y!= 0)
x!= 0是否简化为x> 0?或者我错在以下方面:
!(x>0 || y>0)
!(x>0) && !(y>0)
((x<=0) && (y<=0))
Run Code Online (Sandbox Code Playgroud)
谢谢.
这样做,虽然:
do
{
i++;
++j;
System.out.println( i * j );
}
while ((i < 10) && (j*j != 25));
Run Code Online (Sandbox Code Playgroud)
我现在正在学习do-while vs,并希望使用while重写上面的java片段(已经声明和初始化).以下重写代码是否正确:
而:
while ((i < 10) && (j*j != 25))
{
i++;
++j;
System.out.println( i * j );
}
Run Code Online (Sandbox Code Playgroud)
干杯
尝试编写程序以读取表示罗马数字(来自用户输入)的字符串,然后将其转换为阿拉伯语形式(整数).例如,I = 1,V = 5,X = 10等.
基本上,采用String类型参数的构造函数必须将字符串(来自用户输入)解释为罗马数字并将其转换为相应的int值.
除了正在进行的以下(还没有编译)之外,还有更简单的方法来解决这个问题:
import java.util.Scanner;
public class RomInt {
String roman;
int val;
void assign(String k)
{
roman=k;
}
private class Literal
{
public char literal;
public int value;
public Literal(char literal, int value)
{
this.literal = literal;
this.value = value;
}
}
private final Literal[] ROMAN_LITERALS = new Literal[]
{
new Literal('I', 1),
new Literal('V', 5),
new Literal('X', 10),
new Literal('L', 50),
new Literal('C', 100),
new Literal('D', 500),
new Literal('M', 1000)
};
public …Run Code Online (Sandbox Code Playgroud)