码迷,mamicode.com
首页 > 编程语言 > 详细

《java 语言程序设计》第1章编程练习

时间:2015-03-05 12:14:15      阅读:172      评论:0      收藏:0      [点我收藏+]

标签:

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 < 5; i++) {
            System.out.println("Welcome to Java");
        }
    }
}

1.3

public class test {
    public static void main(String[] args) {
        System.out.println("   J    A    V     V    A");
        System.out.println("   J   A A    V   V    A A");
        System.out.println("J  J  AAAAA    V V    AAAAA");
        System.out.println(" JJ  A     A    V    A     A");
    }
}

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.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) {
        double s = (9.5*4.5-2.5*3)/(45.5-3.5);
        System.out.println(s);  //0.8392857142857143
    }
}

1.6

public class test {
    public static void main(String[] args) {
        int s=0;
        for(int i=0; i<10; ++i) {
            s+=i;
        }
        System.out.println(s);  //45
    }
}

1.7

public class test {
    public static void main(String[] args) {
        double pi = 0;
        double t;
        int m=1;
        for(int i=1; i<12121358; i++) {
            t=1.0/(2*i-1);
            t*=m;
            pi+=t;
            m*=-1;
        }
        pi*=4;
        System.out.println(pi); //3.1415927360890374
    }
}

 

《java 语言程序设计》第1章编程练习

标签:

原文地址:http://www.cnblogs.com/archimedes/p/4314816.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!