package com.newer.test;import java.util.*;public class FahrenheitToCelsius extends Conversion{
private int fahrenhei;
public FahrenheitToCelsius(){
}
Scanner sc = new Scanner(System.in); //错误在这个分号上面,搞不懂了
this.fahrenhei = sc.nextInt();
public double convert(){
return (fahrenhei - 32) * 5 / 9.0; // 摄氏温度=(华氏温度-32)*5/9。
}
}
—————————————————————————————————————————package com.newer.test;public abstract class Conversion {
public abstract double convert();
}——————————————————
报这个错误
//Multiple ers at this line
// - Watchpoint:FahrenheitToCelsius [access and modification] - sc
// - Syntax error on token ";", invalid AssignmentOperator
private int fahrenhei;
public FahrenheitToCelsius(){
}
Scanner sc = new Scanner(System.in); //错误在这个分号上面,搞不懂了
this.fahrenhei = sc.nextInt();
public double convert(){
return (fahrenhei - 32) * 5 / 9.0; // 摄氏温度=(华氏温度-32)*5/9。
}
}
—————————————————————————————————————————package com.newer.test;public abstract class Conversion {
public abstract double convert();
}——————————————————
报这个错误
//Multiple ers at this line
// - Watchpoint:FahrenheitToCelsius [access and modification] - sc
// - Syntax error on token ";", invalid AssignmentOperator
public class FahrenheitToCelsius extends Conversion {
private int fahrenhei; public FahrenheitToCelsius() {
Scanner sc = new Scanner(System.in);//错误在这个分号上面,搞不懂了
this.fahrenhei = sc.nextInt();
} public double convert(){
return (fahrenhei - 32) * 5 / 9.0; // 摄氏温度=(华氏温度-32)*5/9。
}
}
this.fahrenhei = sc.nextInt();
其实是这一行放的位置不对。
我只想知道为什么这样写会报错
不能出现执行语句的。this.fahrenhei = sc.nextInt();
这是一条执行语句,它应该在一个方法里,或在{}括起来的代码块里,而楼主直接在类里,所以报错。
照一楼可以的。