*5.15 (Display the ASCII character table) Write a program that prints the characters in the ASCII character table from ! to ~. Display ten characters per line. The ASCII table is shown in Appendix B. Characters are separated by exactly one space.
5.15(显示ASCII字符表)编写一个程序,从中打印ASCII字符表中的字符!至~。每行显示十个字符。ASCII表如附录B所示。字符之间仅用一个空格分隔。
代码如下:
public class Unite5Test15
{
public static void main(String[] args)
{
int num = 0;
for(char ch = 33;ch < 126;ch++)
{
System.out.print(ch+" ");
num++;
if(num % 10 == 0)
{
System.out.println();
}
}
}
}
结果如下:
*5.24 (Sum a series) Write a program to sum the following series:
*5.24(求和系列)编写一个程序来求和以下系列:
代码如下:
public class Unite5Test24
{
public static void main(String[] args)
{
double sum = 0;
for(int i = 1;i <= 97;i = i+2)
{
double a = 1.0*i/(i+2);
sum = sum + a;
}
System.out.println("结果为:"+sum);
}
}
结果为: