《java 语言程序设计》第1章编程练习
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 } }
作者:wuyudong
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利.
如果觉得本文对您有帮助,可以对作者进行小额【赞助】