1.输出学号班级和姓名
public class XingMing { public static void main(String[] args) { System.out.println("计算机1902 28 王运聪"); } }
2.输出以下图形
*
***
*****
***
*
public class TuXing { public static void main(String [] args) { for(int a = 1;a<=3;a++){ for(int b = 1;b<=(3-a);b++){ System.out.print(" "); } for(int c = 1;c<=2*a-1;c++){ System.out.print("*"); } System.out.print("\n"); } for(int a =2;a>=1;a--) { for(int b = 2;b>=a;b--){ System.out.print(" "); } for(int c = 1;c<=2*a-1;c++){ System.out.print("*"); } System.out.print("\n"); } } }
3.定义两个整型变量a=5 b=8 求平方和并输出
public class Sum { public static void main(String[] args) { int a = 5; int b = 8; System.out.println(a*a + b*b); System.out.println((a+b)*(a+b)); } }