T7
public class CountE {
public static void main(String args[])
{
int i;
int n = 1;
double e = 1;// 注意e取值为1而并不是0,如果是0则进入死循环,因为if语句永远不成立
for (i=1; ;i++ )
{
n = n * i;
e = e + 1.0/n;
if ( Math.abs(e-2.71828) < 1e-5 )//注意取绝对值
break;
}
System.out.println("e = "+e);
}
}
T8
public class ChangeArray {
public static void main(String [] args)
{
for (int i = 1; i<=9; i++)
{
int array[] = new int[i];
for (int j = 0; j<i; j++)//注意j小于而不是小于等于i,不然会使系统报错
{
array[j] = i*(j+1);
System.out.print(i+"*"+(j+1)+"="+array[j]);
System.out.print(" ");
}
System.out.println("");
}
}
}
T9
public class Output {
public static void main(String [] args)
{
int a, b, i;
for (a = 0; a<=7; a++)
{
for (i=1; i<=a+1; i++)
{
System.out.print("*");
for (b = 0; b<=a-1; b++)
{
System.out.print(".");
}
}
System.out.println("");
}
}
}