Created
August 1, 2013 19:58
-
-
Save dhust/6134679 to your computer and use it in GitHub Desktop.
printf()
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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