M
M
maslinych2016-10-28 00:16:43
Java
maslinych, 2016-10-28 00:16:43

How to get a word from an array?

Assignment at school) (I reached the end but I can’t display (
I display the number of the NW variable (let’s say 2), but I need the NW itself to be displayed
Code:

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--;
        }
    }
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
B
bropa, 2016-11-03
@bropa

Made through reflection based on your question. There will be questions write
Some lines commented out, some variables removed.

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());
        }
    }
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question