public class Stringtoint {
public static void main(String[] args) {
int w = new Integer(args[0]).intValue();
int h = Integer.parseInt(args[1]);
for(int i=0;i<w;i++)
{
StringBuffer sb = new StringBuffer();
for(int j=0;j<h;j++); //循环出错,原因是多了一个' ; '
{
sb.append("*");
}
System.out.println(sb.toString());
}
}
}
*********************************
import java.util.*;
public class TestVector {
public static void main(String[] args)
{
Vector v = new Vector();
int b = 0;
System.out.println("Please enter number:");
while(true); //这里又出现 ;了啊啊啊,所以才有break必须出现在循环switch中的提示
{
try
{
b = System.in.read(); //int b = System.in.read();b在{}中,所以,他的有效范围就在{}中
}
catch(Exception e)
{
e.printStackTrace();
}
if(b == '\r'||b == '\n')
{
break ; //错误: 在 switch 或 loop 外部中断
}
else
{
int num = b - '0';
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.println(sum);
}
}