本文整理汇总了Java中java.util.Scanner.nextDouble方法的典型用法代码示例。如果您正苦于以下问题:Java Scanner.nextDouble方法的具体用法?Java Scanner.nextDouble怎么用?Java Scanner.nextDouble使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.util.Scanner
的用法示例。
在下文中一共展示了Scanner.nextDouble方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: main
import java.util.Scanner; //导入方法依赖的package包/类
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.print("Enter your age in years: ");
double age = input.nextDouble();
System.out.print("Enter your maximum heart rate: ");
double rate = input.nextDouble();
double fb = (rate - age) * 0.65;
System.out.println("Your ideal fat-burning heart rate is " + fb);
System.out.print("\nPlease enter an Integer: ");
while(!input.hasNextInt()) {
input.nextLine();
System.out.print("Invalid integer; please enter an integer: ");
}
int i = input.nextInt();
System.out.println("Done");
}
示例2: readInput
import java.util.Scanner; //导入方法依赖的package包/类
/**
* Reads the input file for data.
*
* @return The data matrix with raw program data.
* @throws IOException In case there are IO problems.
*/
private static double[][] readInput() throws IOException {
// IO-related objects and variables
final String INPUT_FILENAME = "resources/Main_08_Input.txt"; // Input file name
Scanner sc = new Scanner(new File(INPUT_FILENAME)); // File scanner
int numOfNums = sc.nextInt(); // The first number in the input file
double[][] out = new double[2][numOfNums]; // Method output data matrix
/*
* Reminder: double[][] out is what becomes the data matrix for the
* whole program. It has a constant width of 2 and a variable height
* of "length" depending on the amount of data to process in the
* input file.
*/
// Assign data from file to array
for (int i = 0; i < numOfNums; i++) {
out[0][i] = sc.nextDouble();
}
// Close Scanner
sc.close();
return out; // Output raw program data
}
示例3: main
import java.util.Scanner; //导入方法依赖的package包/类
public static void main(String[] args) {
// entrada = 3 notas
// Seria o prompt do java script
Scanner sc = new Scanner(System.in);
System.out.println("Digite o valor da nota 1:");
double nota1 = sc.nextDouble();
System.out.println("Digite o valor da nota 2:");
double nota2 = sc.nextDouble();
System.out.println("Digite o valor da nota 3:");
double nota3 = sc.nextDouble();
// processamento = calcular media
double media = (nota1 + nota2 + nota3)/3;
// saida = condicao do aluno (Reprovado, aprovado, recuperacao)
if (media <= 5) {
System.out.println("Reprovado");
} else if (media > 5 && media < 7) {
System.out.println("Recuperacao");
} else {
System.out.println("Aprovado");
}
}
示例4: testViaUserInput
import java.util.Scanner; //导入方法依赖的package包/类
private static void testViaUserInput(Network network) {
@SuppressWarnings("resource")
Scanner in = new Scanner(System.in);
while (true) {
int size = network.getInputLayer().size();
double[] input = new double[size];
for (int i = 0; i < size; i++) {
System.out.println("Enter Input " + (i + 1) + ": ");
input[i] = in.nextDouble();
}
network.clear();
network.setInput(input);
network.calculate();
for (int i = 0; i < network.getOutput().length; i++) {
System.out.println("Output: " + Math.round(network.getOutput()[i]) + " [" + network.getOutput()[i] + "]");
}
}
}
示例5: 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++;
}
}
示例6: main
import java.util.Scanner; //导入方法依赖的package包/类
public static void main(String[] args) throws IOException{
BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
Scanner sc = new Scanner(System.in);
System.out.println("Initialize Bank Account: ");
System.out.print("Input initial balance: ");
double bal = sc.nextDouble();
System.out.print("Input rate of interest: ");
double rate = sc.nextDouble();
BankAcct acc = new BankAcct(bal, rate);
System.out.print("Input password to calcualte interest: ");
String pass = input.readLine();
BankAcct.Private_Methods obj = new BankAcct(bal, rate).new Private_Methods();
if(pass.equals(obj.password)){
System.out.print("Input time for interest: ");
int time = sc.nextInt();
obj.calculateInterest(time);
}else
System.out.println("Login Failed!! Wrong Password");
}
示例7: main
import java.util.Scanner; //导入方法依赖的package包/类
public static void main(String[] args) {
Scanner x = new Scanner(System.in);
int n = x.nextInt();
double r = x.nextDouble();
double PI = Math.PI;
double a[][] = new double[n][2];
for (int i = 0; i < n; i++) {
for (int j = 0; j < 2; j++) {
a[i][j] = x.nextDouble();
}
}
double sum = 0;
for (int i = 0; i < n - 1; i++) {
sum += func(a[i][0], a[i + 1][0], a[i][1], a[i + 1][1]);
}
sum += func(a[0][0], a[n - 1][0], a[0][1], a[n - 1][1]) + 2 * PI * r;
System.out.printf("%.2f", sum);
}
示例8: main
import java.util.Scanner; //导入方法依赖的package包/类
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
double n;
System.out.print("Valor qualquer: ");
n = input.nextDouble();
input.close();
if (n > 0)
System.out.println("O valor informado é positivo");
else if (n < 0)
System.out.println("O valor informado é negativo");
else
System.out.println("O valor informado é nulo");
}
示例9: main
import java.util.Scanner; //导入方法依赖的package包/类
public static void main(String[] args) {
// entrada = preco de custo + percentual
// Seria o prompt do java script
Scanner sc = new Scanner(System.in);
System.out.println("Digite o preco custo:");
double precoCusto = sc.nextDouble();
System.out.println("Digite o percentual:");
float percentual = sc.nextFloat();
// processamento = valor de venda
double valorVenda = (percentual / 100 * precoCusto) + precoCusto;
// saida = valor da venda
// Forma de arredondar um valor
valorVenda = Math.round(valorVenda);
System.out.println("Valor de venda = " + valorVenda);
}
示例10: main
import java.util.Scanner; //导入方法依赖的package包/类
public static void main(String[] args) {
/* Save input */
Scanner scan = new Scanner(System.in);
int size = scan.nextInt();
double [] X = new double[size];
double [] Y = new double[size];
for (int i = 0; i < size; i++) {
X[i] = scan.nextDouble();
}
for (int i = 0; i < size; i++) {
Y[i] = scan.nextDouble();
}
scan.close();
System.out.format("%.3f", spearman(X, Y));
}
示例11: main
import java.util.Scanner; //导入方法依赖的package包/类
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
double lambda = scan.nextDouble();
int k = scan.nextInt();
scan.close();
System.out.println(poisson(k, lambda));
}
示例12: parsePoint
import java.util.Scanner; //导入方法依赖的package包/类
/**
* Parses a WKT point data from the intialized reader
* @return Point data as a Coordinate
* @throws IOException if couldn't parse coordinate values
*/
protected Coord parsePoint() throws IOException {
String coords = readNestedContents(reader);
Scanner s = new Scanner(coords);
double x,y;
try {
x = s.nextDouble();
y = s.nextDouble();
} catch (RuntimeException e) {
throw new IOException("Bad coordinate values: '" + coords + "'");
}
return new Coord(x,y);
}
示例13: main
import java.util.Scanner; //导入方法依赖的package包/类
public static void main(String[] args)
{
double money;
double consumption;
Scanner sc = new Scanner(System.in);
System.out.println("请输入是否是会员(是(y)/否(n)):");
String a = sc.next();
if("y".equals(a))
{
System.out.println("请输入购物金额:");
consumption = sc.nextDouble();
if(consumption >= 20)
{
money = consumption * 0.75;
System.out.println("实际支付:" + money);
}
else
{
money = consumption * 0.8;
System.out.println("实际支付:" + money);
}
}
else
{
System.out.println("请输入购物金额:");
consumption = sc.nextDouble();
if(consumption >= 100)
{
money = consumption * 0.9;
System.out.println("实际支付:" + money);
}
else
{
money = consumption;
System.out.println("实际支付:" + money);
}
}
sc.close();
}
示例14: main
import java.util.Scanner; //导入方法依赖的package包/类
public static void main(String[]args)
{
Scanner sc = new Scanner(System.in);
System.out.print("圆的半径是:");
double radius = sc.nextDouble();;
double pi = 3.14159;
double area = pi * radius * radius;
System.out.println("圆的面积是:" + area);
sc.close();
}
示例15: main
import java.util.Scanner; //导入方法依赖的package包/类
public static void main (String[]args)
{
Scanner sc = new Scanner(System.in);
System.out.println("请输入是否是会员:(y/n)");
String a = sc.next();
double money = 0;
if(a.equals("y"))
{
System.out.println("请输入购物金额:");
money = sc.nextDouble();
if(money >= 200.0)
{
System.out.println("实际支付"+money*0.75);
}
else
{
System.out.println("实际支付"+money*0.8);
}
}
else
{
System.out.println("请输入购物金额:");
money = sc.nextDouble();
if(money >= 100.0)
{
System.out.println("实际支付"+money*0.9);
}
else
{
System.out.println("实际支付"+money);
}
}
sc.close();
}