0

Super newbie question here.

I'm taking a course on Udemy and trying to run some of the scripts from the lessons I've taken. As far as I can see, I've entered the script exactly as it's in the lesson video.

Regardless, for some reason, the script just barrels through all of the lines containing Scanner, takes no user input, and somehow runs to the script's end.

I'm using IntelliJ IDEA for all of this. When I run the script, a console window does not even appear for user input.

Below is an example script:

import java.util.Scanner;

public class J4AB_S6_L4 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        System.out.println("The VIP Lounge");

        System.out.print("Age:");
        int age = scanner.nextInt();

        if (age >= 18) {
            System.out.println("Do you have a VIP pass? yes/no:");
            String vipPassReply = scanner.next();
            if (vipPassReply.equals("yes")) {
                System.out.println("Thanks, go in.");
            } 
                else {
                System.out.println("Sorry you must have a VIP Pass.");
            }
        }
    }

And another script, using Switch.

import java.util.Scanner;

public class J4AB_S6_L7 {
// This is an intro to switch statement syntax.

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int num = scanner.nextInt();

        switch (num) {
            case 1:
                System.out.println("You entered one.");
                break;
            case 2:
                System.out.println("You entered two.");
                break;
            default:
                System.out.println("Dude, why'd you enter that?");
                break;
        }
    }

Why is the script just running through without any user input? Is this a matter of the script itself or IntelliJ IDEA?

  • Can't reproduce, this script [works fine](https://i.imgur.com/hvrRSav.png) in IntelliJ IDEA. – CrazyCoder Dec 29 '19 at 06:33
  • Thanks for your comment! Do you have some setting where the console window for user input comes up? Could you even tell me what this window is called ( Console, terminal, etc. )? I think this may be the issue overall, that I have my settings such that this thing does not appear. – Thomas Magnus Dec 29 '19 at 17:10
  • It's the Run window: https://www.jetbrains.com/help/idea/run-tool-window.html. Share a screenshot/video of the issue. Are there any errors in the [idea.log](https://intellij-support.jetbrains.com/hc/articles/207241085)? – CrazyCoder Dec 29 '19 at 20:05
  • Before I say anything, a huge thanks for all your help. The following is a MediaFire link to a QuickTime video of my screen. Sorry I couldn't get this on Youtube, had formatting issues: http://www.mediafire.com/file/0y99ch5f5g2b9el/Scanner_Help.mov/file – Thomas Magnus Dec 29 '19 at 21:24
  • The issue is really just that I can't access the Run window at all. I think this may be due to an old Plug-In of some sort, or maybe an issue with the recent update I did ( to the 2019.3 edition ). Similar issues reported here: https://stackoverflow.com/questions/22504569/intellij-idea-13-1-is-missing-run-debug-windows – Thomas Magnus Dec 29 '19 at 21:25
  • IntelliJ IDEA builds all the files in the project before run, if any of the files has the compilation error, the code will not run. Your video shows that L3 and L1 files have errors that must be fixed (non-static method nextInt() cannot be referenced from static context). One of the ways to fix this error is to make the `nextInt()` method static. If you want to be able to run other files that do compile while some of the files still have errors, please [refer to this answer](https://stackoverflow.com/questions/16784703/enable-partial-compilation-in-intellij-idea). – CrazyCoder Dec 29 '19 at 21:39

0 Answers0