import java.io.*;
public class TC {
double x,y;
TC(double x,double y){
if(x<=5)
y=1-x*x;
else
y=x-5;
}
void show()
{ System.out.println(y);
}
public static void main(String[] args) {
double M;
double N=0.0;
System.out.println("input");
BufferedReader in=new BufferedReader(new InputStreamReader(System.in);
M=double .parseDouble(in.readLine());
N=double .parseDouble(in.readLine());
TC r=new TC(M,N);
r.show();
}
}
public class TC {
double x,y;
TC(double x,double y){
if(x<=5)
y=1-x*x;
else
y=x-5;
}
void show()
{ System.out.println(y);
}
public static void main(String[] args) {
double M;
double N=0.0;
System.out.println("input");
BufferedReader in=new BufferedReader(new InputStreamReader(System.in);
M=double .parseDouble(in.readLine());
N=double .parseDouble(in.readLine());
TC r=new TC(M,N);
r.show();
}
}
解决方案 »
- 关于set对象的add方法
- 从JTextField向数据库中插入数据
- JTabbedPane+WebBrowser 怎么会出来莫名其秒的空白???
- 既是applet又是application的java程序的关闭问题。
- 到底是先static还是先constructor啊?为什么两个程序的执行顺序截然相反呢?【请教】
- 为什么我没有oracle.sql.BLOB.empty_lob()这个函数?
- 我想用java打开mp3,怎么办?
- java里面有没有象MSDN一样的帮助系统啊???
- 在java里有关编码和解码的问题:比如对中文编码成BASE64或quoted-printable或者是其他的,应该用什么类什么方法?请赐教!!
- 这是什么问题
- 请大家帮个忙?想问个简单的问题
- 一道笔试题
楼主【zhangbin55661】截止到2008-07-13 10:28:38的历史汇总数据(不包括此帖):
发帖的总数量:7 发帖的总分数:140 每贴平均分数:20
回帖的总数量:3 得分贴总数量:0 回帖的得分率:0%
结贴的总数量:4 结贴的总分数:80
无满意结贴数:0 无满意结贴分:0
未结的帖子数:3 未结的总分数:60
结贴的百分比:57.14 % 结分的百分比:57.14 %
无满意结贴率:0.00 % 无满意结分率:0.00 %
楼主加油
TC(double x,double y){
if(x <=5)
y=1-x*x;
else
y=x-5;}
注意构造方法里的x,y和field x,y没有什么关系。因为名字覆盖的问题。在构造方法中出现这种情况的时候用this来指明field x和 y。
比如 this.x和 this.y,直接用的话是参数列表里的x和y
public class TC {
double x,y;
TC(double x,double y){
this.x=x;
this.y=y;}
void show()
{
if(x <=5)
y=1-x*x;
else
y=x-5;
System.out.println(y);
}
public static void main(String[] args) throws Exception{
double M;
double N=0.0;
System.out.println("input");
BufferedReader in=new BufferedReader(new InputStreamReader(System.in));
M=new Double(in.readLine()).doubleValue();
N=new Double(in.readLine()).doubleValue();
TC r=new TC(M,N);
r.show();
}
}
double不是对象
public class TC {
double x,y;
TC(double x,double y){
this.x=x;
this.y=y;}
void show()
{
if(x <=5)
y=1-x*x;
else
y=x-5;
System.out.println(y);
}
public static void main(String[] args) throws Exception{
double M;
double N=0.0;
System.out.println("input");
BufferedReader in=new BufferedReader(new InputStreamReader(System.in));
M=new Double(in.readLine()).doubleValue();
N=new Double(in.readLine()).doubleValue();
TC r=new TC(M,N);
r.show();
}
}
double x, y; Tc(double x, double y) {
if (x <= 5)
y = 1 - x * x;
else
y = x - 5; } void show() {
System.out.println(y);
} public static void main(String[] args) {
double M;
double N=0.0;
System.out.println("input");
BufferedReader in=new BufferedReader(new InputStreamReader(System.in));
try {
M=Double .parseDouble(in.readLine());
N=Double .parseDouble(in.readLine()); Tc r=new Tc(M,N);
r.show();
} catch (NumberFormatException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
可以了,不过你的程序只会打印0.0,,,
构造方法里===>>this.y
import java.io.*; public class TC {
double x,y;
TC(double x,double y){
if(x <=5)
this.y=1-x*x;
else
this.y=x-5;
}
void show()
{
System.out.println(y);
}
public static void main(String[] args) throws Exception{
double M;
double N=0.0;
System.out.println("input");
BufferedReader in=new BufferedReader(new InputStreamReader(System.in));
M=Double.parseDouble(in.readLine());
N=Double.parseDouble(in.readLine());
TC r=new TC(M,N);
r.show();
}
}
[/code]
错误1:这里的double应该是封装类d需要大写
错误2:System.in后面查一个括号
错误3:构造里面的y前应该有一个(this.),否则每次运行都是0.0
import java.io.*; public class TC {
double x,y;
TC(double x,double y){
if(x <=5)
this.y=1-x*x;
else
this.y=x-5;
}
void show()
{
System.out.println(y);
}
public static void main(String[] args) throws Exception{
double M;
double N=0.0;
System.out.println("input");
BufferedReader in=new BufferedReader(new InputStreamReader(System.in));
M=Double.parseDouble(in.readLine());
N=Double.parseDouble(in.readLine());
TC r=new TC(M,N);
r.show();
}
}