java实现输入的数字相加,在php中就是一个foreach
import java.io.IOException;
import java.util.*;
public class lesson8 {
public static void main(String [] args)
{
int b=0;
Vector v = new Vector();
System.out.print("please enter number:");
while(true)
{
try {
b = System.in.read();
} catch (IOException e1) {
e1.printStackTrace();
}
if()
break;
else
{
v.addElement(new Integer(num));
}
}
int sum = 0;
Enumeration e = v.elements();
while(e.hasMoreElements())
{
Integer intObj = (Integer)e.nextElement();
sum+=intObj.intValue();
}
System.out.print(sum);
}
}
另一个是实现数组的顺序排序,在php中可以实现多种排序,并且比java简单asort
import java.util.*;
public class lesson9 {
public static void main(String [] args)
{
ArrayList al = new ArrayList();
al.add(new Integer(1));
al.add(new Integer(13));
al.add(new Integer(2));
System.out.print(al.toString());
Collections.sort(al);
System.out.print(al.toString());
}
}



Comment:


