Skip to content

Instantly share code, notes, and snippets.

@dhust
Created August 1, 2013 19:32
Show Gist options
  • Save dhust/6134479 to your computer and use it in GitHub Desktop.
Save dhust/6134479 to your computer and use it in GitHub Desktop.
IO - Complex example
// Declare variables
Scanner input = new Scanner(System.in);
String favoriteFood;
int numberOfCandyBarsUserCanEat;
// Ask user for favorite food
System.out.print("What is your favorite food? ");
// Store response
favoriteFood = input.next();
// Ask user number of candy bars they can eat
System.out.print("How many candy bars can you eat? ");
// Store response
numberOfCandyBarsUserCanEat = input.nextInt();
// Print their responses
System.out.printf("Favorite food = %s, number of candy bars you can eat = %d", favoriteFood, numberOfCandyBarsUserCanEat);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment