//根据行、列、字符打印对应行数的字符
//比如:行:4,列:4,字符#,则打印相应的效果
####
####
####
####
1.方法的返回类型
2.方法的名字
3.方法的形参
4.方法体,判断
import java.util.Scanner; public class 类名 { public static void main(String[] arg) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); print(n); } public static void print(int a) { for (int i = 0; i < a; i++) { for (int j = 0; j < a; j++) { System.out.print("#"); } System.out.println(); } } }进阶版
import java.util.Scanner; public class practice2 { public static void main(String[] arg) { Scanner sc = new Scanner(System.in); int a = sc.nextInt(); int b = sc.nextInt(); print(a,b,'#'); } public static void print(int row, int col, char a) { for (int i = 0; i < row; i++) { for (int j = 0; j < col; j++) { System.out.print(a); } System.out.println(); } } }
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)