Skip to content

Instantly share code, notes, and snippets.

@dhust
Created August 1, 2013 19:58
Show Gist options
  • Save dhust/6134679 to your computer and use it in GitHub Desktop.
Save dhust/6134679 to your computer and use it in GitHub Desktop.
printf()
// Printing text
System.out.printf("Hello class");
// Printing a String
String name = "Dexter";
System.out.printf("Hello %s", name);
// Printing an integer
int number = 8;
System.out.printf("My number is %d", number);
// Printing a decimal
float number = 8.54f;
System.out.printf("My number is %f", number);
// Printing text with more than one variable
Scanner inputInt = new Scanner(System.in);
int userNumber, userNumber2;
System.out.print("Please enter a number: ");
userNumber = inputInt.nextInt();
System.out.print("Please enter a number: ");
userNumber2 = inputInt.nextInt();
System.out.printf("The numbers are %d and %d", userNumber, userNumber2);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment