目录
一、基础案例
1.打印菱形
2.打印玫瑰花
3.在控制台输出三角图形:
4.找出以下代码的错误,并修改
二、扩展案例
1.定义字符串变量并输出
操作步骤描述
*
* *
* *
* *
* *
* *
*
public class Test04 { public static void main(String[] args) { System.out.println(" *"); System.out.println(" * *"); System.out.println(" * *"); System.out.println("* *"); System.out.println(" * *"); System.out.println(" * *"); System.out.println(" *"); } }
操作步骤描述
{@}
/|\
|
提示: “\”在java中是转移符,如果要在字符串中写一个”\”,你需要写为”\\”
public class Test05 { public static void main(String[] args) { System.out.println("{@}"); System.out.println("/|\\"); System.out.println(" | "); } }
操作步骤描述
*
**
***
****
public class Test06 { public static void main(String[] args) { System.out.println("*"); System.out.println("**"); System.out.println("***"); System.out.println("****"); } }
public class Test07_01 {
public static void main(String[] args) {
int a;
System.out.println(a);
{
int c = 20;
System.out.println(c);
}
c = 30;
System.out.println(c);
}
}
public class Test07_02 {
public static void main(String[] args) {
int x = 2;
{
int y = 6;
System.out.println("x is " + x);
System.out.println("y is " + y);
}
y = x;
System.out.println("x is " + x);
}
}
public class Test07 { public static void main(String[] args) { int a; //a未赋值不能直接输出 //System.out.println(a); { int c = 20; System.out.println(c); } //变量c出了括号范围,所以变量c要重新定义 //c = 30; //System.out.println(c); int x = 2; { int y = 6; System.out.println("x is " + x); System.out.println("y is " + y); } //变量y出了括号范围,所以变量y要重新定义 //y = x; System.out.println("x is " + x); } }
操作步骤描述
public class Test01 { public static void main(String[] args) { String s="不忘初心,方得始终"; System.out.println(s); } }