input.nextDouble()
时间: 2023-11-20 16:19:12 浏览: 39
This is a Java method that reads the next inputted double value from the console. It is commonly used in Java programs to read input from the user.
Here's an example of how it can be used:
Scanner input = new Scanner(System.in);
double number = input.nextDouble();
In this example, we create a new Scanner object called "input" that reads input from the console. We then call the "nextDouble" method on this object to read the next double value inputted by the user. This value is then stored in a variable called "number".
相关问题
package Text4; import java.util.Scanner; public class MakeLinear { Scanner input=new Scanner(System.in); System.out.println("Enter x1,y1,x2,y2,x3,y3,x4,y4:"); double x1=input.nextDouble(); double y1=input.nextDouble(); double x2=input.nextDouble(); double y2=input.nextDouble(); double x3=input.nextDouble(); double y3=input.nextDouble(); double x4=input.nextDouble(); double y4=input.nextDouble(); LinearEquation text=new LinearEquation(); }
这段代码存在语法错误,因为它直接在类中执行了一些语句,而这些语句应该在方法中执行。你需要将这些语句放到一个方法中,例如:
```java
package Text4;
import java.util.Scanner;
public class MakeLinear {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.println("Enter x1,y1,x2,y2,x3,y3,x4,y4:");
double x1 = input.nextDouble();
double y1 = input.nextDouble();
double x2 = input.nextDouble();
double y2 = input.nextDouble();
double x3 = input.nextDouble();
double y3 = input.nextDouble();
double x4 = input.nextDouble();
double y4 = input.nextDouble();
LinearEquation text = new LinearEquation();
}
}
```
注意,我在代码中添加了一个 `main` 方法,它是 Java 程序的入口方法。在这个方法中,我将原来的代码放到了 `main` 方法中,并添加了一个类的实例化语句。当你修复了这个语法错误后,还需要检查代码逻辑是否正确,以确保程序能够按照预期执行。
在类中实现主要功能: 要求输入一个人的身高和体重,并打印出他的 BMI,同时显示BMI是高是低。对于一个成年人,BMI的值的含义如下: BMI<18.5,表示偏瘦 18.5<=BMI<25.0,表示正常 25.0<=BMI<30.0,表示超重 BMI>=30.0,表示过胖 关键步骤如下: Scanner input = new Scanner(Syste m.in); double weight, height; double bmi; System.out.println("请输入你的体重(单位:k g)"); weight =input.nextDouble(); System.out.println("请输入你的身高(单位: m)"): height = input.nextDouble(); bmi = weight / (height * height); System.out.println("你的身高质量指数是:"+ bmi); //补充代码,完成功能 if(){}else if(){ else if(){ else{
可以在类中添加如下代码来实现主要功能:
Scanner input = new Scanner(System.in);
double weight, height;
double bmi;
System.out.println("请输入你的体重(单位:kg)");
weight = input.nextDouble();
System.out.println("请输入你的身高(单位:m)");
height = input.nextDouble();
bmi = weight / (height * height);
System.out.println("你的身高质量指数是:" + bmi);
if (bmi < 18.5) {
System.out.println("你的BMI偏瘦");
} else if (bmi < 25.0) {
System.out.println("你的BMI正常");
} else if (bmi < 30.0) {
System.out.println("你的BMI超重");
} else {
System.out.println("你的BMI过胖");
}
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)