Если числа из условия записаны в переменные rank, score, passingScore, russianLanguage, то получение можно получить, если:
rank ≤ 10 или score ≥ passingScore и russinaLanguage = 1
В C++ ИЛИ обозначается как ||, а И - как &&.
Код (C++):
#include <iostream>
int main() {
int rank, score, passingScore, russianLanguage;
std::cin >> rank >> score >> passingScore >> russianLanguage;
if ((rank <= 10) || ((score >= passingScore) && (russianLanguage == 1))) {
std::cout << "YES";
} else {
std::cout << "NO";
}
import java.util.Scanner;
public class OldYears {
public static void main(String[] args) {
int years = readConsole("Enter age of the person", 0, 231 - 1);
System.out.printf("Enter value: %s;%sAnswer: %s;", years, System.lineSeparator(), getResult(years));
public static int readConsole(String answer, int startRange, int endRange) {
Scanner read = new Scanner(System.in);
boolean value = false;
int result = 0;
while (!value) {
System.out.printf("%s: ", answer);
try {
result = Integer.valueOf(read.next());
if (!(value = result >= startRange && result <= endRange)) {
System.out.printf("Incorrect value [%s <= value <= %s]. Try again.%s", startRange, endRange, System.lineSeparator());
} catch (NumberFormatException e) {
System.out.println("The value is not number. Try again.");
return result;
public static String getResult(int years) {
String result;
if (years >= 0 && years <= 6) {
result = "BABY";
} else if (years > 6 && years <= 17) {
result = "SCHOOLCHILD";
} else if (years > 17 && years <= 64) {
result = "ADULT";
} else if (years > 64 && years <= 120) {
result = "ELDER";
result = "GHOST";
Объяснение:
Если числа из условия записаны в переменные rank, score, passingScore, russianLanguage, то получение можно получить, если:
rank ≤ 10 или score ≥ passingScore и russinaLanguage = 1
В C++ ИЛИ обозначается как ||, а И - как &&.
Код (C++):
#include <iostream>
int main() {
int rank, score, passingScore, russianLanguage;
std::cin >> rank >> score >> passingScore >> russianLanguage;
if ((rank <= 10) || ((score >= passingScore) && (russianLanguage == 1))) {
std::cout << "YES";
} else {
std::cout << "NO";
}
}
import java.util.Scanner;
public class OldYears {
public static void main(String[] args) {
int years = readConsole("Enter age of the person", 0, 231 - 1);
System.out.printf("Enter value: %s;%sAnswer: %s;", years, System.lineSeparator(), getResult(years));
}
public static int readConsole(String answer, int startRange, int endRange) {
Scanner read = new Scanner(System.in);
boolean value = false;
int result = 0;
while (!value) {
System.out.printf("%s: ", answer);
try {
result = Integer.valueOf(read.next());
if (!(value = result >= startRange && result <= endRange)) {
System.out.printf("Incorrect value [%s <= value <= %s]. Try again.%s", startRange, endRange, System.lineSeparator());
}
} catch (NumberFormatException e) {
System.out.println("The value is not number. Try again.");
}
}
return result;
}
public static String getResult(int years) {
String result;
if (years >= 0 && years <= 6) {
result = "BABY";
} else if (years > 6 && years <= 17) {
result = "SCHOOLCHILD";
} else if (years > 17 && years <= 64) {
result = "ADULT";
} else if (years > 64 && years <= 120) {
result = "ELDER";
} else {
result = "GHOST";
}
return result;
}
}
Объяснение: