Java Tutorial 3: Hello Scanner and Random!


Video is ready, Click Here to View ×

Hello and welcome to Java! I’m going to be, in the coming weeks, uploading tutorial after tutorial on java! This specific video shows how to get text user input from the command line as well as how to generate random numbers and use if else conditions and statements. This series will get you from no java experience at all to networking, creating multithreaded servers, getting user input, writing to and reading from files, 2D graphics, and more! Have any questions? Feel free to leave them in…

47 thoughts on “Java Tutorial 3: Hello Scanner and Random!

  1. I tried to do another ifelse statement but it didn't work. It said that there was a syntax error. if statement runs { } and after that goes the else { } (of course on different lines) it said there was a syntax error for else.

  2. Hey! I'm having a problem with the last line. Just take a look,please! That code is bugging me. The first number is randomly generated number between 10-15 but the next number is always ALWAYS 210. Before you say yes i changed names it's always the same.Anyone explain?
    System.out.println(random.nextInt(5)+10 + "," + random.nextInt(5)+10);

  3. This video is awesome! Explained the Scanner function perfect that I actually know what you're talking about. Thank you! -From current college student getting BA in CIS and certification in Java Programming

  4. Hi Maxwell, you taught very well. But I want to make a random number generator between a range of numbers. For instance: 10 to 15. Then some of the random number should pop up between this range. Any help please?
    Once again, thanks a lot for the nice tutorials.

  5. Can someone please explain me this:
    we made a scanner object using the new keyword
    that created a scanner named "in" which is a instance of the scanner class
    first we used the "in" to assign the UserName
    and then we are using the same "in" to accept the PasscodeFromUser ??
    How can it assign two different variables if object is just an INSTANCE of a class ?

  6. Sorry if im a bit late but when ever I do

    System.out.println("Access DENIED by: " + userName);

    an error pops up saying " syntax error on token "else" delete this token"? please help

  7. I don't get the String userName = in.nextLine(); and the difference between int passcodeFromUser= in.nextInt();
    Is the nextInt used only for int, or can it be used for doubles too. Also is the Line for strings and chars, or just strings? Also what is the for and what is the () for. Please if you can answer any of these questions(or all), that would really help me out. Thanks for reading! I'm a noob so that's why I'm asking.

  8. 12. int passcodeFromUser-in.nextInt();
    On this line i get the error: ''Syntax error on token "passcode from user"; = expected after this token. My class looks exactly like Maxwells, any thoughts?


  9. i seem to be having issues with your last instruction regarding a random number within a specific range. ive placed the code- random.nextInt(5)+10); as a 4th generated number and it has generated the number 310 twice in a row for this instruction. Nothing obvious seems to be at fault either.

  10. Hello Maxwell! First of all, your tutorials are fantastic. I love them. Secondly, I'm having problems with my if/else statements. Every time I type Hi it just returns hi has been added to the list. Can you please help me? Here's my code:
    package austinIoeMain;

    import java.util.Scanner;

    public class AustinIoeMain {

        public static void main(String[] args) {
            String hi = "Hi";
            Scanner in = new Scanner(;
            System.out.println("Hello, I am Austin Ioe. I am a nearly fully functional Artificial Intelligence.");
            System.out.println("Ask me anything, I'll try to make sense of it. If not, I'll just tell you I don't understand.");
            String input = in.nextLine();
            if (input == hi)
                System.out.println(input + " has been added to the list of words to understand.");


  11. Edit: I understand my mistake now. I thought it was System.out.printIn with a capital i instead of a lowercase L. Thanks to +ShaZy Sanjrani and +Hawkflight120 (The bird that is a youtuber) I understood my mistake. Also thanks to +TheDeceivingEye for helping, even though I already knew my error I appreciate it.

    I have a problem with the seventh line: Scanner in = new Scanner(;
    I get a warning that says "Resource leak: 'in' is never closed".
    One problem I've noticed is that I'm not able to write under the text printed like you could at 7:24 in the video.

    I've searched for a solution on the internet for a while but I can't find a solution I understand. Does anyone reading this comment know whats wrong and/or how to fix it? According to me I wrote exactly what was written on the video. All code I have written down is written here(I can't use printIn and uses print instead, otherwise I always gets an error):

    1. import java.util.*;
    2. public class Tutorial3 
    3. {
    5. public static void main(String[] args) 
    6. {
    7. Scanner in = new Scanner(;
    8. System.out.print("Welcome! Please enter your name!");
    9. String userName = in.nextLine();
    10. System.out.print("Welcome " + userName + "!");
    11. }
    13. }

Leave a Reply

Your email address will not be published. Required fields are marked *