Mr. V Scanner Example

 avatar
unknown
java
2 years ago
829 B
6
Indexable
import java.util.Scanner;
public class ScannerNotes{
   public static void main(String[]args){
    Scanner reader = new Scanner(System.in);
	System.out.println("What is your name?");
	String name = reader.nextLine();
	System.out.println("What is the temperature?");
	int temperature = reader.nextInt();
	reader.nextLine(); //Note the reader.nextLine(); added after the int and before the String!!			
System.out.println("What is the weather?");
	String weather = reader.nextLine();
	System.out.println("What is your class average?");
	double average = reader.nextDouble();
	System.out.println("Hi "+ name + "! "+ "It is currently "+ temperature +" degrees and "+weather+".");
	System.out.println("Today is a great day to get a "+ average +" average!");

	reader.close(); // use the close() method to avoid a resource leak.
   }
}
Editor is loading...