Java Code Examples for java.util.Scanner#nextShort()
The following examples show how to use
java.util.Scanner#nextShort() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Exercise_05_44.java From Intro-to-Java-Programming with MIT License | 6 votes |
public static void main(String[] args) { Scanner input = new Scanner(System.in); // Prompt the user to enter a short integer System.out.print("Enter an integer: "); short number = input.nextShort(); String bits = ""; // Holds the bits // Get the 16 bits for the integer for (int i = 0; i < 16; i++) { bits = (number & 1) + bits; number >>= 1; } // Display result System.out.println("The bits are " + bits); }
Example 2
Source File: HeatingMain_1457.java From AlgoCS with MIT License | 5 votes |
public static void main(String[] args) { PrintWriter writer = new PrintWriter(new OutputStreamWriter(System.out)); Scanner x = new Scanner(System.in); short n = x.nextShort(); double s = 0; for (int i = 0; i < n; i++) { s += x.nextInt(); } writer.printf("%.6f", s / n); writer.close(); }