Monthly Archives: March 2017

Java example: input from keyboard

To read the value of a variable from the input console: add the following code at the very beginning of the class file: import java.util.Scanner; declare a Scanner object: Scanner kScanner; use the scanner to read the variable value; example: A=kScanner.nextInt(); Primitive data types: byte – signed integers in [-128,127] (8 bit) short – signed

Java example: factorial

More info on factorial: While-Do version: Comments: line 5: declare 2 integer variables, one is called N and one is called F line 7: N is initialized with a value of 4 line 9: F is initialized with the same value of N line 11: the While-Do starts with a condition check if the