import java.io.*;
^这儿缺一个分号
^这儿缺一个分号
解决方案 »
- java 一个小问题,希望明解
- 请教swing美工问题
- 关于增加字符串
- 急!哪位老兄用过jmf??
- 关于正确表达式的问题
- 关于Class.forName("mypackage.myclass").newInstance();的问题
- JB为何点用资源程序大,运行速度太慢,而borland系列产品象DELPHI,BCB都比它快。
- 假如s1="abcdef",我要插入"123"变成abc123def",有类似SQL中的stuff()函数么?!
- 新手上路,debug的问题.
- 图片处理的问题!给分!一定的!
- 在没有安装jre的机器上运行java程序,怎么样写bat文件临时指定我自带的jre?
- 两个大阶乘相除溢出。急救。
这样会提示错误的阿
Math math1=new Math(),math2=new Math(),math3=new Math(),math4=new Math();
出错了吧
仔细看看
嘿嘿
D:\下载\程序\liyan.java:16: class Out is public, should be declared in a file named Out.java
public class Out{
^
D:\下载\程序\liyan.java:38: class Maths is public, should be declared in a file named Maths.java
public class Maths{
^
D:\下载\程序\liyan.java:7: Math() has private access in java.lang.Math
Math math1=new Math(),math2=new Math(),math3=new Math(),math4=new Math();
^
D:\下载\程序\liyan.java:7: Math() has private access in java.lang.Math
Math math1=new Math(),math2=new Math(),math3=new Math(),math4=new Math();
^
D:\下载\程序\liyan.java:7: Math() has private access in java.lang.Math
Math math1=new Math(),math2=new Math(),math3=new Math(),math4=new Math();
^
D:\下载\程序\liyan.java:7: Math() has private access in java.lang.Math
Math math1=new Math(),math2=new Math(),math3=new Math(),math4=new Math();
^
D:\下载\程序\liyan.java:9: cannot resolve symbol
symbol : method plus (int,int)
location: class java.lang.Math
mat1.getout(a,'+',b,math1.plus(a,b));
^
D:\下载\程序\liyan.java:10: cannot resolve symbol
symbol : method minus (int,int)
location: class java.lang.Math
mat2.getout(a,'-',b,math2.minus(a,b));
^
D:\下载\程序\liyan.java:11: cannot resolve symbol
symbol : method multi (int,int)
location: class java.lang.Math
mat3.getout(a,'*',b,math3.multi(a,b));
^
D:\下载\程序\liyan.java:12: cannot resolve symbol
symbol : method div (int,int)
location: class java.lang.Math
mat4.getout(a,'/',b,math4.div(a,b));
^
D:\下载\程序\liyan.java:34: cannot resolve symbol
symbol : method println (int,int,int,java.lang.String)
location: class java.io.PrintStream
System.out.println(+a,+c,+b,"="+d);
^
D:\下载\程序\liyan.java:57: possible loss of precision
found : float
required: int
return((float)a/b);
^
12 errorsProcess completed.
我用的是JCredtor LE 编译的,可是为什么在Math math1=new Math(),math2=new Math(),math3=new Math(),math4=new Math();
处会出错了?
1.import java.io.*少了一个分好
2.Math math1=new Math(),math2=new Math(),math3=new Math(),math4=new Math();
按照你的意思,应该是Maths吧
3.mat1.getout(a,'+',b,math1.plus(a,b));按照你的定义应该只有3个参数,你却给了4个,并且类型不匹配
4.System.out.println(a,c,b,"="+d);是不是应该写为System.out.println(a+c+b"="+d);
5.public int div(int a,int b){
return((float)a/b);
}
div返回的是int,而你return的是float
public class liyan
{
public static void main(String[] args)
{
int a=130,b=45;
Maths math1=new Maths();
Maths math2=new Maths();
Maths math3=new Maths();
Maths math4=new Maths();
Out mat1=new Out();
Out mat2=new Out();
Out mat3=new Out();
Out mat4=new Out();
mat1.getout(a,'+',b,math1.plus(a,b));
mat2.getout(a,'-',b,math2.minus(a,b));
mat3.getout(a,'*',b,math3.multi(a,b));
mat4.getout(a,'/',b,math4.div(a,b));
}
} class Out{
private int a;
private int b;
private int d;
private char c;
public int getouta(){
return a;
}
public int getoutb(){
return b;
}
public int getoutd(){
return d;
}
public char getoutc(){
return c;
}
public void getout(int a,char c,int b,int d){
System.out.println(+a,+c,+b,"="+d);
}
} class Maths{
private int a;
private int b;
public int geta(){
return a;
}
public int getb(){
return b;
}
public int plus(int a,int b){
return(a+b);
}
public int minus(int a,int b){
return(a-b);
}
public int multi(int a,int b){
return(a*b);
}
public int div(int a,int b){
return((float)a/b);
}
}其出错提示是
--------------------Configuration: j2sdk1.4.2 <Default>--------------------
D:\下载\程序\liyan.java:40: cannot resolve symbol
symbol : method println (int,int,int,java.lang.String)
location: class java.io.PrintStream
System.out.println(+a,+c,+b,"="+d);
^
D:\下载\程序\liyan.java:63: possible loss of precision
found : float
required: int
return((float)a/b);
^
2 errorsProcess completed.这句话要怎么改?
return((float)a/b);
}
2。 public void getout(int a,char c,int b,int d){
System.out.println(""+a+c+b+"="+d);
}
还有,你不要用可能是关健字并类库的名称做为类名,以免造成不必要的错误!
最后把类放在包中!也就是在开头加:package语句!并放在对应的目录下!如,你的src为你的源代码的目录,那么package a.b.c;public class abc;那么你的abc.java就放在src/a/b/c/abc.java中!
{
public static void main(String[] args)
{
int a=130,b=45;
Maths math1=new Maths(),math2=new Maths(),math3=new Maths(),math4=new Maths();
Out mat1=new Out(),mat2=new Out(),mat3=new Out(),mat4=new Out();
mat1.getout(a,b,(char)math1.plus(a,b));
mat2.getout(a,b,(char)math2.minus(a,b));
mat3.getout(a,b,(char)math3.multi(a,b));
mat4.getout(a,b,(char)math4.div(a,b));
}
}
class Out{
private int a;
private int b;
public int d;
private char c;
public int getouta(){
return a;
}
public int getoutb(){
return b;
}
public int getoutd(){
return d;
}
public char getoutc(){
return c;
}
public void getout(int a,int b,char c){
System.out.println("d="+(a+b+(int)c));
}
}
class Maths{
private int a;
private int b;
public int geta(){
return a;
}
public int getb(){
return b;
}
public int plus(int a,int b){
return(a+b);
}
public int minus(int a,int b){
return(a-b);
}
public int multi(int a,int b){
return(a*b);
}
public int div(int a,int b){
return(a/b);
}
}
楼主的Math math1=new Math(),math2=new Math(),math3=new Math(),math4=new Math();都少写了一个s,调用函数getout(a,'+',b,math1.plus(a,b))括号中的参数要和你自己定义的参数一致,还有一些小的错误,自己在好好看看吧。
public class liyan
{
public static void main(String[] args)
{
int a=130,b=45;
Maths math1=new Maths();
Maths math2=new Maths();
Maths math3=new Maths();
Maths math4=new Maths();
Out mat1=new Out();
Out mat2=new Out();
Out mat3=new Out();
Out mat4=new Out();
mat1.getout(a,'+',b,math1.plus(a,b));
mat2.getout(a,'-',b,math2.minus(a,b));
mat3.getout(a,'*',b,math3.multi(a,b));
mat4.getout(a,'/',b,math4.div(a,b));
}
} class Out{
private int a;
private int b;
private int d;
private char c;
public int getouta(){
return a;
}
public int getoutb(){
return b;
}
public float getoutd(){
return d;
}
public char getoutc(){
return c;
}
public void getout(int a,char c,int b,float d){
System.out.println(""+a+c+b+"="+d);
}
} class Maths{
private int a;
private int b;
public int geta(){
return a;
}
public int getb(){
return b;
}
public int plus(int a,int b){
return(a+b);
}
public int minus(int a,int b){
return(a-b);
}
public int multi(int a,int b){
return(a*b);
}
public float div(int a,int b){
return((float)a/b);
}
}为什么Maths math1=new Maths(),math2=new Maths(),math3=new Maths;在JCredtor LE 下不能这样写了?
Maths math1=new Maths(),math2=new Maths(),math3=new Maths();
我试了可以JCredtor LE 这样写