运行基本扫描程序

时间:2014-02-23 09:09:38

标签: java eclipse

我正在尝试编写一个给出液体量的程序,我可以计算出一杯水和一茶匙糖的量,这是液体量的四倍。为什么我写的这个程序不起作用,你们中的任何一个人是否可能引导我朝着正确的方向前进?我已经工作了几个小时,似乎无法找到问题所在。

谢谢!

/* package whatever; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
class Ideone
{
public static void main (String[] args) throws java.lang.Exception
{
// Scanner scan = new scanner(system.in);
double liquid, cups;
double teasoons;
System.out.println("Dishwashing liquid?");
liquid = scan.nextdouble();
cups = 4*liquid;
teaspoons = 4*liquid
System.out.println(cups+teaspoons and grams);
scan.close();

}
}

2 个答案:

答案 0 :(得分:0)

更改此行

System.out.println(cups+teaspoons and grams);

到这个

System.out.println(cups+ "teaspoons and grams");

另外,要注意班级名称,必须以大写字母开头。

Scanner scan = new Scanner(system.in);

总而言之,您的代码应如下所示:

public static void main (String[] args) throws java.lang.Exception
{
    double liquid, cups;
    double teaspoons;
    Scanner scan = new Scanner(system.in);

    System.out.println("Dishwashing liquid?");
    liquid = scan.nextdouble();
    cups = 4*liquid;
    teaspoons = 4*liquid
    System.out.println(cups + "teaspoons and grams");
    scan.close();

}

答案 1 :(得分:0)

import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
class Ideone
{
public static void main (String[] args) throws java.lang.Exception
{
 Scanner scan = new Scanner(System.in);
double liquid, cups;
double teaspoons;
System.out.println("Dishwashing liquid?");
liquid = scan.nextDouble();
cups = 4*liquid;
teaspoons = 4*liquid;
System.out.println(cups+"teaspoons and grams");
scan.close();

}
}