From the course: Learning Java 11

Unlock the full course today

Join today to access over 22,500 courses taught by industry experts or purchase this course individually.

Input and output in Java

Input and output in Java - Java Tutorial

From the course: Learning Java 11

Start my 1-month free trial

Input and output in Java

- So far, we've learned how to output information to the user using System.out.println(). We've created several variables and printed out their values to the user as well as concatenated their values to String literals. In this lesson we'll look at how we can create a program that allows the user to input information affecting the program's output. Thinking back to our student program, we might need to update a student's GPA. With some updates to the code, we can let the user dynamically change the value of a student's GPA. In the previous lesson, we wrote a print statement that tells a given student their GPA. Before having the user update their GPA, we should ask the user what value they want to update the GPA to and that's the print statement I've added here. Next we need to get access to the user's input and update the value of the student GPA variable. To do this, we can create a Scanner with System.in and save the Scanner in the variable labeled input. This is the opposite of…

Contents