@maslinych

Как вывести слово из массива?

Задание в школе)(Я дошёл до конца а вывести не могу(
У меня выводится число переменной NW(допустим 2), а мне нужно чтобы выводилось само NW
Код:
import java.util.Scanner;
import java.util.regex.Matcher;

public class qq1 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int input, x, x1, x2, y, y2, y1, q, N, S, W, E, w, e, r, NW, NE, SW, SE;
        x1 = sc.nextInt();
        y1 = sc.nextInt();
        x2 = sc.nextInt();
        y2 = sc.nextInt();
        x = sc.nextInt();
        y = sc.nextInt();
        input = x + y;
        N = y2;
        W = x1;
        E = x2;
        S = y1;
        NW = x1 + y2;
        NE = x2 + y2;
        SE = x2 + y1;
        SW = x1 + y1;
        int[] nums = {N, W, E, S, NW, NE, SE, SW};
        int upSearch = input;
        int downSearch = input;
        while (true) {
            for (int num : nums) {
                if (num == upSearch || num == downSearch) {
                        System.out.println(nums[]);
                    return;
                }
            }
            upSearch++;
            downSearch--;
        }
    }
}
  • Вопрос задан
  • 346 просмотров
Пригласить эксперта
Ответы на вопрос 1
@bropa
Сделал через рефлексию исходя из твоего вопроса. Будут вопросы пиши
Некоторые строчки закоментил, некоторые переменные удалил.
import java.lang.reflect.Field;
import java.util.Scanner;

public class TempClass {

    static int N, W, E, S, NW, NE, SE, SW;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int input, x, y, q, w, e, r;
        W = sc.nextInt();
        S = sc.nextInt();
        E = sc.nextInt();
        N = sc.nextInt();
        x = sc.nextInt();
        y = sc.nextInt();
        input = x + y;
        NW = N + W;
        NE = E + N;
        SE = E + S;
        SW = W + S;
//        int[] nums = {N, W, E, S, NW, NE, SE, SW};
//        int upSearch = input;
//        int downSearch = input;
        Field[] fields = TempClass.class.getDeclaredFields();
        System.out.println(fields.length);
        for (Field field : fields) {
            System.out.println(field.getName());
        }
    }
}
Ответ написан
Комментировать
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы