tilenbox:
怒鳴るのコードでは、私は値が1000と9999の間ですが、do..whileループの場合のロジックがオフと思われる場合は、繰り返しになっているdo..whileループの場合を作ります。
import java.util.Scanner;
public class Nal2 {
public static void main(String[] ARGS) {
int i = 0;
Scanner bralnik = new Scanner(System.in);
do {
System.out.printf("Insert a 4 digit num: ");
i = bralnik.nextInt();
} while (i >= 1000 && i <= 9999);
System.out.print("Oi");
}
}
このdosen't作業が、作品怒鳴るコード。
import java.util.Scanner;
public class Nal2 {
public static void main(String[] ARGS) {
int i = 0;
Scanner bralnik = new Scanner(System.in);
do {
System.out.printf("Insert a 4 digit num: ");
i = bralnik.nextInt();
} while (i <= 1000 || i >= 9999);
System.out.print("Oi");
}
}
Shouldn &&
作品の代わりに||
?
私は本当にこのことについて困惑しています。
私はInteliJのIDEAに2019年3月4日CEを使用しています
Ibrahimli崇高:
public static void main(String[] args) {
int i = 0;
Scanner bralnik = new Scanner(System.in);
do {
System.out.printf("Insert a 4 digit num: ");
i = bralnik.nextInt();
} while (!(i<=1000||i>=9999));
System.out.print("Oi");
}
あなただけのOR(||)を使用してコードを記述する場合は、上記の書き込み。!結果を逆にしない論理的である、結果が真である場合はfalseを返します。あなたが書くOR、OR条件のいずれかに該当する場合はtrueを返し、ので、あなたの第二のスニペットは仕事をしません。