路漫漫其修远兮,吾将上下而求索 - 百度文库
习题解答
第一章 作业题
1.
public class Hello{
public static void main (String args[ ]){
System.out.pintln(“早上好,good Morning”); } } 2.
import java.applet.*; import java.awt.*;
public class Boy extends Applet { public void paint(Graphics g) { g.setColor(Color.blue);
g.drawString(\你好,hello\ } }
第二章 作业题
1.
public class ZuoYe2_1{
public static void main (String args[ ]){ char c='а';
System.out.println(\字母\在unicode表中的顺序位置:\ System.out.println(\字母表:\ while(c<='я'){
System.out.print(\ c=(char)(c+1); } 1
路漫漫其修远兮,吾将上下而求索 - 百度文库
}
}
2.
import java.util.*;
public class ZuoYe2_2{
public static void main (String args[ ]){
Scanner reader=new Scanner(System.in); long chengji=1; int m=0;
while(reader.hasNextInt()){ int x=reader.nextInt(); m=m+1;
chengji=chengji*x; }
System.out.println(m+\个数的乘积为\ } }
第三章 作业题
1.
import java.util.*;
public class ZuoYe3_1{
public static void main (String args[ ]){
Scanner reader=new Scanner(System.in); double y=0,x=0;
x=reader.nextDouble(); if(x<0)
y=-1+2*x; else if(x==0) y=-1; else if(x>0) y=-1+3*x;
System.out.println(y); } } 2.
public class ZuoYe3_2{ 2
路漫漫其修远兮,吾将上下而求索 - 百度文库
public static void main(String args[]){ int sum=0,m=3,n=7,a=1; while(a<=1000){
if(a%m==0&&a%n==0) sum=sum+a; a++; }
System.out.println(\ } } 3.
public class ZuoYe3_3 {
public static void main(String args[]) {
long sum=0,a=8,item=a,n=10,i=1;
for(i=1;i<=n;i++)
{ sum=sum+item;
item=item*10+a; }
System.out.println(sum); } } 4.
public class ZuoYe3_4 {
public static void main(String args[]) {
double sum=0,a=1,b=1,fuhao=1,item=a/b; int i=1;
while(i<=1000) {
sum=sum+fuhao*item; i++;
fuhao=fuhao*(-1); b=b+2; item=a/b; }
System.out.println(\ } 3