private static void question40(int num1) {
System.out.println("Q40");
if (num1 % 2 == 0) {
System.out.println("even");
} else {
System.out.println("odd");
}
}
private static void question41(int num1) {
System.out.println("Q41");
if (num1 > 0 && num1 <= 9) {
System.out.println(num1);
}
}
private static void question42(int num1, int num2, int num3) {
System.out.println("Q42");
// if ((num1 < num2 && num2 < num3) || (num1 == num2 || num2 == num3)) {
if (num1 <= num2 && num2 <= num3){
System.out.println("ok");
} else {
System.out.println("NG");
}
}
* <p>
*Imaginary numbers are squared to negative numbers.
*Numbers other than imaginary numbers are real numbers.
*The multiple solution has one solution.
*/
private static void question43(int a, int b, int c) {
System.out.println("Q43");
int d = b * b - 4 * a * c;
if (d > 0) {
System.out.print("Two real solutions");
} else if (d == 0) {
System.out.print("Multiple solution");
} else {
System.out.println("Imaginary solution");
}
}
private static void question44(int money, int doller) {
System.out.println("Q44");
//Yen converted to dollars: Yen you want to convert ÷ Yen price per dollar
int yen = money / doller;
//1 cent is 1/$ 100
//TODO Round off to see if it can be truncated properly
System.out.println("How much is one dollar?");
System.out.println(money + "Yen is" + yen + "In dollars" + "is");
}
private static void question45(int m) {
System.out.println("Q45");
//610 yen up to 1700m
int taxi = 610;
int price = 0;
//If it is 1700m or less, it will be 610 yen
if (m < 1700) {
price = taxi;
} else {
//Exceeded distance over 1700m
double increase = m - 1700;
//How many times every 313m has come
double number = increase / 313;
//Spending 80 yen on the number of times
//Advance the number of times with the first decimal point
price = Double.valueOf(taxi + (Math.ceil(number) * 80)).intValue();
}
System.out.println("Taxi fare" + price + "It's a yen");
}
private static void question46(int human) {
System.out.println("Q46");
int nyuzyou1 = 600;
int nyuzyou2 = 550;
int nyuzyou3 = 500;
int price = 0;
//600 yen for one person
//500 yen per person for 20 or more
if (human < 5) {
price = human*nyuzyou1;
//550 yen per person for 5 or more and less than 20
}else if (human < 20) {
price = human*nyuzyou2;
//500 yen per person for 20 or more
}else {
price = human*nyuzyou3;
}
System.out.println("Admission is" + price + "It's a yen");
}
Create a program that displays the value of each variable. Simply changing the order and displaying is not enough. Be sure to swap the values of variables. In the case of the execution example below, first, from the state where 2 is input to the variable a and 5 is input to b, the value of a is changed to 5 and the value of b is changed to 2.
private static void question47(int a, int b) {
System.out.println("Q47");
//Display the value of the variable before exchange
System.out.println( "Before replacement: a=" + a + " b=" + b );
//Assign to a temporary variable
int x = a;
a = b;
b = x;
//After replacement
System.out.println("After replacement: a=" + a + " b=" + b);
}
*while statement
private static void question48(int number) {
System.out.println("Q48");
System.out.println("number:" + number);
for (int i = 1, answer = number; answer != 1; i++) {
answer = answer % 2 == 0 ? answer / 2 : answer * 3 + 1;
System.out.println(i + ": " + answer);
}
}
*Tab between values(\t)Use to make a gap.
*TODO Don't put out the last tab
private static void question49() {
System.out.println("Q49");
for (int i = 1; i < 10; i++) {
for (int j = 1; j < 10; j++) {
System.out.print(i * j + "\t");
}
System.out.println("");
}
}
private static void question50() {
System.out.println("Q50");
for (int i = 1; i <= 100; i++) {
if(i % 3 == 0 && i % 5 == 0) {
//When it is a multiple of 3 and a multiple of 5
System.out.println("foobar");
//When it is a multiple of 3
} else if(i % 3 == 0){
System.out.println("foo");
} else if(i % 5 == 0) {
System.out.println("bar");
}else {
//If none of the above apply
System.out.println(i);
}
}
}
private static void question51(int money) {
System.out.println("Q51");
int hyaku = money/100;
int zyuu = (money-(hyaku*100))/10;
//100 yen ball
System.out.println("100 yen ball" + hyaku + "It is a piece");
//10-yen coin
System.out.println("10-yen coin" + zyuu + "It is a piece");
}
private static void question52(int year) {
System.out.println("Q52");
boolean check = false;
//The remainder of dividing the year by 4 is 0
if (year % 4 == 0 && year % 100 == 0 && year % 400 == 0) {
check = true;
} else {
check = true;
}
// String s = b ? "true" : "false";
System.out.println(check ? "It's a leap year." : "It's not a leap year.");
}
private static void question53(int number) {
System.out.println("Q53");
System.out.print(number + "=");
//The initial value of the For statement is 2 because the prime number is 2 or more.
for (int i = 2; i <= number; i++) {
if (number % i == 0) {
//If divisible, i is a prime number.
//If it is not divisible, it is not a prime number.
number /= i;
if (number == 1) {
System.out.print(i);
}else {
System.out.print(i + "×");
}
}
}
}
Recommended Posts