Hello, very new... I've just been playing around with a program that's meant to ask the user for their name and age...
Here's the code :
import java.util.Scanner; public class Noerng { public static void main(String[] args) { Scanner name1 = new Scanner(System.in); System.out.println("Enter your first name :"); String firstName = name1.nextLine(); Scanner name2 = new Scanner(System.in); System.out.println("Enter your second name :"); String secondName = name2.nextLine(); System.out.println("hello there " + firstName + " " + secondName); String fullName = firstName + " " + secondName; Scanner age = new Scanner(System.in); System.out.println("How old are you?"); int userAge = age.nextInt(); System.out.println("You're " + fullName + ", and you are " + userAge + " years old."); if (userAge < 21) { System.out .println("I don't think you're old enough to drink in America"); } else { System.out.println("I think you're old enough to drink in America"); } name1.close(); name2.close(); age.close(); } }
Would be great to have feedback to anything that's a bit off / not the done thing...
Is there a way to close all of the scanners at once?
cheers
--- Update ---
not sure why eclipse is formatting line 33 to a different one...