1

I'm really confused why my program is not working. It'll compile and run, but no output will be printed to the console. I'm using the "Run Configurations" feature in the Eclipse IDE and placing my input into the "Program Arguments" section. My input is below. The first line indicates how many processes will have to run. My program is supposed to perform the basic action of printing out the relationship between number_1 and number_2

3
10 20
20 10
10 10

I'm using a Scanner object, but it doesn't seem to be taking in the input properly.

import java.util.Scanner;

public class Operator {
    public static void main(String[] args) {

    Scanner input = new Scanner(System.in);

    int runs = input.nextInt();
    Integer num1;
    Integer num2;

    for(int i = runs; i > 0; i--){
        num1 = input.nextInt();
        num2 = input.nextInt();

        switch(num1.compareTo(num2)){
            case 1:
                System.out.println(">");
                break;
            case 0:
                System.out.println("=");
                break;
            case -1:
                System.out.println("<");
                break;
        }
    }

    input.close();
}

}

2
  • The input should be coming from System.in not command line arguments -try prompting for some input System.out.println ("Enter num1"); num1 = input.nextInt(); Commented Feb 6, 2019 at 0:39
  • 1
    Scanner doesn't read your command line arguments Commented Feb 6, 2019 at 0:48

1 Answer 1

1

Values in the 'Program Arguments' section of the Run Configuration are passed to the program in the args parameter of main.

You can specify a file containing the input in the 'Standard Input and Output' section on the 'Common' tab of the Run Configuration.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.