第一章
1.1 public class Test{
    public static void main(String[] args){
        System.out.println("Welcome to Java !");
        System.out.println("Welcome to Computer Science !");
        System.out.println("Programming is fun .");
    }
}
1.2 public class Test{
    public static void main(String[] args){
        for(int i = 0;i <= 4;i++){
        System.out.println("Welcome to Java !");
        }
    }
}
1.3 public class Test{
    public static void main(String[] args){
        System.out.println("  ]");
        System.out.println("  ]");
        System.out.println("]  ]");
        System.out.println(" ]]");
    }
}
public class Test{
    public static void main(String[] args){
        System.out.println("  A");
        System.out.println("  A A");
        System.out.println(" AAAAA");
        System.out.println("A      A");
    }
}
public class Test{
    public static void main(String[] args){
        System.out.println("V    V");
        System.out.println(" V  V");
        System.out.println("  V V");
        System.out.println("  V");
    }
}
1.4 public class Test{
    public static void main(String[] args){
        System.out.println("a  a^2 a^3");
        System.out.println("1  1  1");
        System.java程序设计教程第三版施霞萍课后答案out.println("2  4  8");
        System.out.println("3  9  27");
        System.out.println("4  16  64");
    }
}
1.5 public class Test{
    public static void main(String[] args){
        System.out.println((9.5*4.5-2.5*3)/(45.5-3.5));
    }
}
1.6 public class Test{
    public static void main(String[] args){
        int i = 1,sum = 0;
        for(;i <= 9;i++)
        sum += i;
        System.out.println(sum);
    }
}
1.7 public class Test{
    public static void main(String[] args){
        System.out.println(4*(1.0-1.0/3+1.0/5-1.0/7+1.0/9-1.0/11));
        System.out.println(4*(1.0-1.0/3+1.0/5-1.0/7+1.0/9-1.0/11+1.0/13));
    }
}
1.8 public class Test{
    public static void main(String[] args){
        final double PI = 3.14;
        double radius = 5.5;
        System.out.println(2 * radius * PI);
        System.out.println(PI * radius * radius);
    }
}
1.9 public class Test{
    public static void main(String[] args){
        System.out.println(7.9 * 4.5);
        System.out.println(2 * (7.9 + 4.5));
    }
}
1.10 public class Test{
    public static void main(String[] args){
        double S = 14 / 1.6;
        double T = 45 * 60 + 30;
        double speed = S / T;
        System.out.println(speed);
    }
}
1.11 public class Test{
    public static void main(String[] args){
        int BN = 312032486; //original person numbers
        double EveryYS,EveryYBP,EveryYDP,EveryYMP;
        EveryYS = 365 * 24 * 60 * 60;
        EveryYBP = EveryYS / 7;
        EveryYDP = EveryYS / 13;
        EveryYMP = EveryYS / 45;
        int FirstYP,SecondYP,ThirdYP,FourthYP,FivthYP;
        FirstYP = (int)(BN + EveryYBP + EveryYMP - EveryYDP);
        SecondYP = (int)(FirstYP + EveryYBP + EveryYMP - EveryYDP);
        ThirdYP = (int)(SecondYP + EveryYBP + EveryYMP - EveryYDP);
        FourthYP = (int)(ThirdYP + EveryYBP + EveryYMP - EveryYDP);
        FivthYP = (int)(FourthYP + EveryYBP + EveryYMP - EveryYDP);
        System.out.println(FirstYP);
        System.out.println(SecondYP);
        System.out.println(ThirdYP);
        System.out.println(FourthYP);
        System.out.println(FivthYP);
    }
}
1.12 public class Test{
    public static void main(String[] args){
        double S = 24 * 1.6;
        double T = (1 * 60 + 40) * 60 + 35;
        double speed = S / T;
        System.out.println(speed);
    }
}
1.13 import java.util.Scanner;
public class Test{
    public static void main(String[] args){
        Scanner input = new Scanner(System.in);
        System.out.println("input a,b,c,d,e,f value please:");
        double a = Double();
        double b = Double();
        double c = Double();
        double d = Double();
        double e = Double();
        double f = Double();
        double x,y;
        x = (e * d - b * f) / (a * d - b * c);
        y = (a * f - e * c) / (a * d - b * c);
        System.out.println("The result is x: "+(int)(x * 1000) / 1000.0);
        System.out.println("The result is y: "+(int)(y * 1000) / 1000.0);    }
}

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。