当前位置: 技术问答>java相关
我是java新手,帮我看一下下面这段程序哪儿有错?
来源: 互联网 发布时间:2015-07-26
本文导语: import java.io.*; public class emp309 { public static void main(String args[]) { float aa; String s; try { System.out.print("Please input a float:"); BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); s=br.readLine(); ...
import java.io.*;
public class emp309
{
public static void main(String args[])
{
float aa;
String s;
try {
System.out.print("Please input a float:");
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
s=br.readLine();
aa=Float.parseFloat(s);
}catch(IOException e) {}
System.out.println(aa);
}
}
public class emp309
{
public static void main(String args[])
{
float aa;
String s;
try {
System.out.print("Please input a float:");
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
s=br.readLine();
aa=Float.parseFloat(s);
}catch(IOException e) {}
System.out.println(aa);
}
}
|
aa没有初始化 float aa=0;
--------------------------------------
import java.io.*;
public class emp309
{
public static void main(String args[])
{
float aa=0;
String s;
try {
System.out.print("Please input a float:");
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
s=br.readLine();
aa=Float.parseFloat(s);
}catch(IOException e) {}
System.out.println(aa);
}
}
--------------------------------------
import java.io.*;
public class emp309
{
public static void main(String args[])
{
float aa=0;
String s;
try {
System.out.print("Please input a float:");
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
s=br.readLine();
aa=Float.parseFloat(s);
}catch(IOException e) {}
System.out.println(aa);
}
}
|
float aa;
String s;
////////
float aa=0;
String s=null;
String s;
////////
float aa=0;
String s=null;
|
初始化aa就行了
float aa=0f;
float aa=0f;
|
你要注意啊!在定义一个变量的时候最好要给它初始化!
只要初始化aa就可以的了!
呵呵!
只要初始化aa就可以的了!
呵呵!