This is a beginner's edition following the basic edition.
public static void question21(int num1, int num2) {
System.out.println("Q21");
int num3 = num1 / num2;
//Display the result of dividing the first value by the second value
System.out.println(num3);
//Display the result of multiplying the result by a second value
System.out.println(num3 * num2);
}
*
* @param num1
*/
public static void question22(int num1) {
System.out.println("Q22");
//If the value is greater than 5 and less than 20
if (num1 > 5 && num1 < 20) {
//If the value is greater than 5 and less than 20
System.out.println("The first value is OK");
}
}
*
* @param num1
*/
public static void question23(int num1) {
System.out.println("Q23");
if (num1 <= -10 || num1 >= 10) {
//value-10 or less, or 10 or more
System.out.println("The first value is OK");
}
}
*
* @param num1
*/
public static void question24(int num1) {
System.out.println("Q24");
//value-When 10 or more and less than 0
if ((num1 >= -10 && num1 < 0) || (num1 >= 10)) {
System.out.println("The first value is OK");
} else {
System.out.println("It's NG");
}
}
public static void question25(int num1) {
System.out.println("Q25");
//value-If less than 10
if (num1 < -10) {
System.out.println("range 1");
// -10 or more and less than 0
} else if (num1 < 0) {
System.out.println("range 2");
//0 or more
} else {
System.out.println("range 3");
}
}
*
* @param num1
*/
public static void question26(int num1) {
System.out.println("Q26");
//Entry example num1(1,2,3,0)
switch (num1) {
//Processing when the value of the expression and the value num1 match
case 1:
System.out.println("one");
break;
case 2:
System.out.println("two");
break;
case 3:
System.out.println("three");
break;
//What to do when the value of an expression does not match the value of any case
default:
System.out.println("others");
}
}
*
* @param num1
*/
public static void question27(int num1) {
System.out.println("Q27");
for (int i = 1; i < num1; i++) {
System.out.println(i);
}
if (num1 == 0) {
System.out.println(0);
}
}
*
* @param num1
*/
public static void question28(int num1) {
for (int i = 1; i <= 10; i++) {
num1 = num1 * i;
}
System.out.println(num1);
}
*
* @param num1
* @param num2
* @param num3
* @param num4
* @param num5
*/
public static void question29(int num1, int num2, int num3, int num4, int num5) {
System.out.println("Q29");
//Show total values
System.out.println(num1 + num2 + num3 + num4 + num5);
}
*
* @param num1
*/
public static void question30(int num1) {
System.out.println("Q30");
for (int i = 0; i < num1; i++) {
System.out.print("*");
}
}
*If the input value is 0 or less, nothing needs to be written.
*
* @param num1
*/
public static void question31(int num1) {
System.out.println("Q31");
for (int i = 1; i < num1; i++) {
System.out.print("*");
// *To be blank every 5
if (i % 5 == 0) {
System.out.print("\t");
}
}
}
public static void question32() {
System.out.println("Q32");
for (int i = 1; i < 20; i++) {
//For multiples of 5
if (i % 5 == 0) {
System.out.println("bar");
} else {
//When not a multiple of 5
System.out.println(i);
}
}
}
*
* @param num1
*/
public static void question33(int num1) {
System.out.println("Q33");
for (int i = 1; i < 10; i++) {
//If i is not the value you entered
if (!(i == num1)) {
System.out.println(i);
}
}
}
*
* @param num1
*/
public static void question34(int num1) {
System.out.println("Q34");
//Input value and input value+If not 1
for (int i = 1; i < 10; i++) {
if ((!(i == num1)) && (!(i == (num1 + 1)))) {
System.out.println(i);
}
}
}
public static void question35(int num1) {
System.out.println("Q35");
// {3, 7, 0, 8, 4, 1, 9, 6, 5, 2}Declare an integer array of size 10 initialized with
int[] array = {3, 7, 0, 8, 4, 1, 9, 6, 5, 2};
System.out.println(array[num1]);
}
*
* @param num1
*/
public static void question36(int num1, int num2) {
System.out.println("Q36");
// {3, 7, 0, 8, 4, 1, 9, 6, 5, 2}Declare an integer array of size 10 initialized with
int[] array = {3, 7, 0, 8, 4, 1, 9, 6, 5, 2};
System.out.println(array[num1] * array[num2]);
}
public static void question37(int num1) {
System.out.println("Q37");
// {3, 7, 0, 8, 4, 1, 9, 6, 5, 2}Declare an integer array of size 10 initialized with
int[] array = {3, 7, 0, 8, 4, 1, 9, 6, 5, 2};
int num2;
num2 = array[num1];
System.out.println(array[num2]);
}
public static void question38() {
System.out.println("Q38");
// {3, 7, 0, 8, 4, 1, 9, 6, 5, 2}Declare an integer array of size 10 initialized with
int[] array = new int[]{3, 7, 0, 8, 4, 1, 9, 6, 5, 2};
//Display the value of the array element with the referenced element number 0
int index = 0;
//Repeat 10 times
for (int i = 0; i < 10; i++) {
//Assign the value of index to the element number index
index = array[index];
//Output the value of the array element when the element number is a
System.out.println(index);
}
}
public static void question39() {
System.out.println("Q39");
// {3, 7, 0, 8, 4, 1, 9, 6, 5, 2}Declare an integer array of size 10 initialized with
int[] array = new int[]{3, 7, 0, 8, 4, 1, 9, 6, 5, 2};
//Repeat 9 times
//Current element number index
for( int index = 0; index < 9; index++){
/**
* index=When 0, currentValue=3,nextIndex=1,nextValue=7
* index=When 1 currentValue=7,nextIndex=2,nextValue=0
* index=When 2 currentValue=0,nextIndex=3,nextValue=8
* */
//Array element value of the element number to be referenced currentValue
int currentValue = array[index];
//Existing element number(index)The next element number of nextIndex
int nextIndex = index + 1;
//NextValue is the value of the array element with the next element number
int nextValue = array[nextIndex];
//Value obtained by subtracting the value of the array element of the next element number from the value of the array element of the element number
System.out.println(currentValue - nextValue);
}
}
}
Recommended Posts