与整数和双精度浮点数有关。

huangapple go评论77阅读模式
英文:

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();

	}
}

huangapple
  • 本文由 发表于 2020年4月6日 13:08:50
  • 转载请务必保留本文链接:https://go.coder-hub.com/61053282.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定