请求高手,怎么用java打出下面的图形。感激!!!
各位高手大佬,我刚学java 我想问下,怎么能打出下面的图形1 1 1 1 1
1 2 2 2 1
1 1 3 2 1
1 2 2 2 1
1 1 1 1 1
刚学完循环,请问这个要怎么输出呀,
数字要求用户输入,在线等····· --------------------编程问答-------------------- 你的数据没问题吧?
貌似看懂规律。
1 1 1 1 1
1 2 2 2 1
1 2 3 2 1
1 2 2 2 1
1 1 1 1 1
这样么? --------------------编程问答-------------------- 完全看不出来有什么规律啊。。。
还是我想的复杂了??? --------------------编程问答--------------------
--------------------编程问答-------------------- 楼上的哥哥,我想问下 就是如果是要求用户输入数字,应该就不是这个样子吧 --------------------编程问答-------------------- 是这样的啊,好像就是别的数字把中间那个数包围起来·· --------------------编程问答--------------------
public class Test {
public static void main(String[] args) {
print(5);
}
static void print(int n){
int index = 0;
int[][] arr = new int[n][n];
for(int i = 0;i < n;i++){
for(int j = 0;j < n;){
if(i == index || j == index || n - i - 1 == index || n - j - 1 == index){
arr[i][j++] = index + 1;
index = 0;
}
else
++index;
}
}
for(int i = 0;i < n;i++){
for(int j = 0;j < n;j++){
System.out.print(arr[i][j] + " ");
}
System.out.println();
}
}
}
真牛! --------------------编程问答-------------------- 1 1 1
1 2 1
1 1 1
这个是用户输入3的结果 --------------------编程问答-------------------- 这个应该是直接输出的,没要求用户输入额。 --------------------编程问答-------------------- 传个参数就好了。。
System.out.println("input number:");
Scanner sc = new Scanner(System.in);
print(sc.nextInt()); --------------------编程问答--------------------
public class Test01 {--------------------编程问答--------------------
public static void main(String[] args) {
final int N = 5;
for (int i = 1 - N; i < N; i++) {
for (int j = 1 - N; j < N; j++) {
System.out.print(N - Math.abs(Math.abs(i) >= Math.abs(j) ? i : j));
}
System.out.println();
}
}
}
111111111
122222221
123333321
123444321
123454321
123444321
123333321
122222221
111111111
补充:Java , Java相关