Chapter 2 - Input/Output and Operators Flashcards
// does what in a program ?
end-of-the-line comment
/*
traditional comment
declare a class
public class Class{}
what two things must be the same in java in order for the application to run?
the class name and the file name
sample code that prints out “Hello World”
System.out.print(“Hello World”);
system.out.printIn
prints output followed by new line
system.out.print
prints output without a new line
system.out.printf
displays formatted data
%s
string
%d
is a format placeholder for int (integer)
%f
double and float
%b
boolean
%n
newline
%t
tab
%20 does what?
creates a 20-character position, right justified
what code does a java program need in order to read user input?
import java.util.Scanner
what code creates a scanner object in java?
Scanner input = new Scanner (System.in)
what code reads user input as a double value?
double number1 = input.nextDouble();
what code reads as an integer?
int number1 =input.nexInt();
what code reads user input as a string ?
String myvalue = input.nextLine();
float vlaue
flloat number1=input.nextFloat();
Boolean
boolean myvalue = input.nextBoolean();
compile a program
javac Program1.java
execute a program
java Program1