本文整理汇总了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;
}