一定。后悔Java基础没学好啊
光求进度去了

北京生存真难(痛苦)说我吸烟特像发哥(窃喜) 想在北京盖一座70层的大厦(理想)。
这不是通不通用的问题,有新方法不用,那要新方法干什么?
呵呵,我喜欢这样用
也是为了推广JDK1.5
都已经出来两年了,居然还有人用1.4
并且这个例子程序里也用了泛型
Vector<Integer> v=new Vector<Integer>();
从终端输入东东时就时输入流麻烦些
import java.io.*;public class Average
{
public static void main(String args[])
{
int sum=0,n=0;
String s=null;
try{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.println(\"Please input the num:\");
while((s=br.readLine())!=null)
{
if(Integer.parseInt(s)==-1) break;
sum+=Integer.parseInt(s);
n++;
System.out.println(\"Please input the num:\");
}
}
catch(Exception e) {}
System.out.println(\"The average is:\"+sum*1.0/n);
}
}
从终端输入东东时就时输入流麻烦些
import java.io.*;public class Average
{
public static void main(String args[])
{
int sum=0,n=0;
String s=null;
try{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.println(\"Please input the num:\");
while((s=br.readLine())!=null)
{
if(Integer.parseInt(s)==-1) break;
sum+=Integer.parseInt(s);
n++;
System.out.println(\"Please input the num:\");
}
}
catch(Exception e) {}
System.out.println(\"The average is:\"+sum*1.0/n);
}
}
写得不错
但是尽量不要在main方法里面写太多东西
最好还是把各个方法分开来写,好一点
泛型是很老的东西了。。。
除非你用一辈子JAVA,要么还是中规中矩写FOR吧。。。新的不一定是好的,这样只会把最基本的包装更深,没有什么技术上的实际意义。这就是为什么这么多年还是用C做为语言经典入门教材的原因。
泛型是很老的东西了。。。
除非你用一辈子JAVA,要么还是中规中矩写FOR吧。。。新的不一定是好的,这样只会把最基本的包装更深,没有什么技术上的实际意义。这就是为什么这么多年还是用C做为语言经典入门教材的原因。
泛型在JAVA中就是新东西,JDK1.5才开始支持
呵呵,那个写并不代表我会忘记基本的写法,只是写习惯了而已
对于要对下标操作的,就不会那样写了