#7 | User input with the Java Scanner | Java tutorial for beginners

Veröffentlicht am: 01 September 2023
auf dem Kanal: Neil Gillies | Coding & Music
306
4

In this video we'll start learning about using the Java scanner to capture some basic user input.

Here is the code used in this lesson:

import java.util.Scanner;
public class AddUp {
public static void main(String[] args) {
// simple program to add two integers and display the result
int firstNum, secondNum, result; // variables
// initialise the scanner
Scanner scanner = new Scanner(System.in);
// ask the user for first number
System.out.println("Please enter your first number");
firstNum = scanner.nextInt();
// ask the user for the second number
System.out.println("Please enter your second number");
secondNum = scanner.nextInt();
// calculate the result
result = firstNum + secondNum;
// display the result to console
System.out.println(firstNum + " plus " + secondNum + " equals " + result);
}
}

Here are the lesson notes:

// The Java Scanner Class can be used for very basic text input
// It can be used alongside the console for basic input and output
// The scanner is an add-on utility that needs to be imported before use
// The scanner is used when learning programming and for testing code without the need for a full UI


Auf dieser Seite können Sie das Online-Video #7 | User input with the Java Scanner | Java tutorial for beginners mit der Dauer stunde minuten sekunde in guter Qualität ansehen, das der Benutzer Neil Gillies | Coding & Music 01 September 2023 hochgeladen hat, den Link mit Freunden und Bekannten teilen, dieses Video wurde auf Youtube bereits 306 Mal angesehen und es wurde von 4 den Zuschauern gefallen. Viel Spaß beim Betrachtenden Zuschauern gefallen!