本文整理匯總了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++;
}
}
示例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++;
}
}
示例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));
}
示例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]);
}
}
示例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;
}