My scanner code with comments
My scanner code with commentsunknown
java
a year ago
1.3 kB
2
Indexable
Never
import java.util.Scanner; // Necessary to memorize! public class Main { // Base code public static void main(String[] args) { // Base code Scanner reader = new Scanner(System.in); // Creates our scanner object (declaration and initialization). Reader is the variable name. System.out.println("What is your name? "); // can NOT be reader.nextInt because they are incompatible types String name = reader.nextLine(); System.out.println("How old are you? "); int age = reader.nextInt(); // Everything must be reader, not scanner. reader.nextLine, because reader is the variable name! reader.nextLine(); // Everytime you do an int or a double, use the command reader.nextLine(); by itself (notice how we don't do it after strings) System.out.println("How big is ur pp???!?!? "); double inches = reader.nextDouble(); reader.nextLine(); System.out.println("What is your favorite food? "); // You can have multiple string inputs! All you have to do is make a new variable (first it was name, then it was food) String food = reader.nextLine(); System.out.println("Hello "+name); System.out.println("You are "+age+" years old"); System.out.println("You like "+food); System.out.println("Ur pp is " + inches + " long, lmao lol (skull)"); reader.close(); } }