當前位置: 首頁>>代碼示例>>Java>>正文


Java Scanner.nextShort方法代碼示例

本文整理匯總了Java中java.util.Scanner.nextShort方法的典型用法代碼示例。如果您正苦於以下問題:Java Scanner.nextShort方法的具體用法?Java Scanner.nextShort怎麽用?Java Scanner.nextShort使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java.util.Scanner的用法示例。


在下文中一共展示了Scanner.nextShort方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: main

import java.util.Scanner; //導入方法依賴的package包/類
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();
}
 
開發者ID:bakhodirsbox,項目名稱:AlgoCS,代碼行數:12,代碼來源:HeatingMain_1457.java

示例2: inputAllBaseTypes

import java.util.Scanner; //導入方法依賴的package包/類
public void inputAllBaseTypes() {    // input all basic data types and output the values
    Scanner input = new Scanner(System.in);
    
    // input the byte
    System.out.print("Enter an byte integer (from -128 to 127): ");
    byte byt = input.nextByte();
    
    // input the short
    System.out.print("Enter an short integer (from -32768 to 32767): ");
    short sho = input.nextShort();

    // input the int
    System.out.print("Enter an integer: ");
    int i = input.nextInt();

    // input the long 
    System.out.print("Enter an long integer: "); 
    long lon = input.nextLong();

    // input the float
    System.out.print("Enter a floating number: ");
    float flo = input.nextFloat();

    // input the double
    System.out.print("Enter a double floating number: ");
    double dou = input.nextDouble();

    // input the char
    System.out.print("Enter a character: ");
    String sTemp = input.next();
    char c = sTemp.charAt(0);

    // input the boolean
    System.out.print("Enter a boolean value: ");
    boolean bool = input.nextBoolean();

    // the outputs: 
    System.out.println("\nThe byte integer is: " + byt);
    System.out.println("The short integer is: " + sho);
    System.out.println("The integer is: " + i);
    System.out.println("The long integer is: " + lon);
    System.out.println("The floating number is: " + flo);
    System.out.println("The double floating number is: " + dou);
    System.out.println("The character is: " + c);
    System.out.println("The boolean value is: " + bool);
}
 
開發者ID:Driveron,項目名稱:Notes,代碼行數:47,代碼來源:InputAllBaseTypes.java


注:本文中的java.util.Scanner.nextShort方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。