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


Java Scanner.hasNextDouble方法代碼示例

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


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

示例1: printAverage

import java.util.Scanner; //導入方法依賴的package包/類
public static void printAverage(Scanner sf, int N) {
  DelayLine<Double> temp = new DelayLine<Double>(N, 0.0);
  out.printf("Temperaturas hora-a-hora e média das últimas %d horas.\n", N);
  out.printf("(As primeiras %d médias não são exatas!)\n", N);
  out.printf("%3s %4s %7s %7s\n", "dia", "hora", "temp.", "média");
  int t = 0;
  while (sf.hasNextDouble()) {
    double nova = sf.nextDouble();
    // Calcula soma das últimas N horas:
    temp.in(nova);
    double somaN = 0.0;
    for (int hora = -N; hora < 0; hora++) {
      somaN += temp.get(hora);
    }
    out.printf("%3d   %02d %7.1f %7.1f\n", t/24, t%24, nova, somaN/N);
    t++;
  }
}
 
開發者ID:ZePaiva,項目名稱:Prog2,代碼行數:19,代碼來源:P103.java

示例2: printAverage

import java.util.Scanner; //導入方法依賴的package包/類
public static void printAverage(Scanner sf, int N) {
  DelayArray<Double> temp = new DelayArray<Double>(N, 0.0);
  out.printf("Temperaturas hora-a-hora e média das últimas %d horas.\n", N);
  out.printf("(As primeiras %d médias não são exatas!)\n", N);
  out.printf("%3s %4s %7s %7s\n", "dia", "hora", "temp.", "média");
  int t = 0;
  while (sf.hasNextDouble()) {
    double nova = sf.nextDouble();
    // Calcula soma das últimas N horas:
    temp.in(nova);
    double somaN = 0.0;
    for (int hora = -N; hora < 0; hora++) {
      somaN += temp.get(hora);
    }
    out.printf("%3d   %02d %7.1f %7.1f\n", t/24, t%24, nova, somaN/N);
    t++;
  }
}
 
開發者ID:ZePaiva,項目名稱:Prog2,代碼行數:19,代碼來源:E1003.java

示例3: scannerDemo2

import java.util.Scanner; //導入方法依賴的package包/類
public static void scannerDemo2() {
	Scanner scan = new Scanner(System.in);

	double sum = 0;
	int m = 0;
	System.out.println("輸入數字求平均,輸入非數字結束!");
	while (scan.hasNextDouble()) {
		double x = scan.nextDouble();
		m = m + 1;
		sum = sum + x;
	}

	System.out.println(m + "個數的和為" + sum);
	System.out.println(m + "個數的平均值是" + (sum / m));
}
 
開發者ID:leon66666,項目名稱:JavaCommon,代碼行數:16,代碼來源:ScannerDemo.java

示例4: main

import java.util.Scanner; //導入方法依賴的package包/類
public static void main(String[] args) {
    int i = 0, t = 0;
    double a[] = new double[999999];
    Scanner x = new Scanner(System.in);
    a[i++] = Math.sqrt(x.nextDouble());
    t++;
    while (x.hasNextDouble()) {
        double d = x.nextDouble();
        a[i++] = Math.sqrt(d);
        t++;
    }
    for (int j = t - 1; j >= 0; j--) {
        System.out.printf("%.4f\n", a[j]);
    }
}
 
開發者ID:bakhodirsbox,項目名稱:AlgoCS,代碼行數:16,代碼來源:ReverseRoot_1001.java

示例5: isDouble

import java.util.Scanner; //導入方法依賴的package包/類
private static boolean isDouble(String string) {
    Scanner scanner = new Scanner(string);
    boolean b = scanner.hasNextDouble();
    scanner.close();

    return b;
}
 
開發者ID:protViz,項目名稱:deisotoper,代碼行數:8,代碼來源:ReadMGF.java


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