英文:
Related to int and double
问题
Scanner keyboard = new Scanner(System.in);
System.out.print("输入矩形的长度:");
double width = keyboard.nextDouble();
System.out.print("输入矩形的宽度:");
double length = keyboard.nextDouble();
double area = length * width;
System.out.print("面积 = " + area);
英文:
strong text
Scanner keyboard = new Scanner(System.in);
System.out.print("Enter rectangle length: ");
double width = keyboard.nextDouble();
System.out.print("Enter rectangle width: ");
double length = keyboard.nextDouble();
double area = length * width;
System.out.print("Area = " + area);
答案1
得分: 1
如果我移除在 Scanner keyboard = new Scanner(System.in);
之前的“strong text”,代码将正常工作。
package adi;
import java.util.Scanner;
public class Greeter {
public static void main(String[] args) {
Scanner keyboard = new Scanner(System.in);
System.out.print("Enter rectangle length: ");
double width = keyboard.nextDouble();
System.out.print("Enter rectangle width: ");
double length = keyboard.nextDouble();
double area = length * width;
System.out.print("Area = " + area);
keyboard.close();
}
}
英文:
If I remove the "strong text" before Scanner keyboard = new Scanner(System.in); will work ok.
package adi;
import java.util.Scanner;
public class Greeter {
public static void main(String[] args) {
Scanner keyboard = new Scanner(System.in);
System.out.print("Enter rectangle length: ");
double width = keyboard.nextDouble();
System.out.print("Enter rectangle width: ");
double length = keyboard.nextDouble();
double area = length * width;
System.out.print("Area = " + area);
keyboard.close();
}
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论