手动输入一个整数n
然后对n*n个整数进行蛇型排列
如:
n=3
排列为
1 2 3
6 5 4
7 8 9
如:n=4
排列为
1 2 3 4 
8 7 6 5
9 10 11 12
16 15 14 13

解决方案 »

  1.   

    public class b{
    static public void main(String args[]){
    b a=new b();
    a.display(4);
    }
    public void display(int Num){
    String Temp="";
    for(int i=1;i<=Num*Num;i++){
    if((i/(Num+1))%2==0){
    Temp=Temp+i;
    }
    else{
    Temp=i+Temp;
    }
    if(i%Num==0){
    System.out.println(Temp);
    Temp="";
    }
    }
    }
    }
    基本上就这个样子 可能Num大点会出错 写得比较仓促 思路就是这样
      

  2.   

    import java.io.BufferedInputStream;
    import java.io.DataInputStream;
    import java.io.IOException;/**
     * @author lbfan
     * 
     */
    public class Snake { /**
     * @param args
     * @throws IOException 
     */
    public static void main(String[] args) throws IOException {
    boolean even = false;
    int temp;
    // BufferedInputStream in = new BufferedInputStream(new DataInputStream(System.in));
    DataInputStream in = new DataInputStream(new BufferedInputStream(System.in));
    int n = Integer.parseInt(in.readLine());
    if((n <= 0) || (n > 100)){
    System.exit(0);
    }
    temp = n -1;
    for(int i = 1; i <= n * n; i ++){
    if(even == false){
    System.out.print(i + " ");
    } else if(even == true){
    System.out.print(i + temp + " ");
    temp -= 2;
    }
    if((i % n) == 0){
    System.out.println();
    temp = n -1;
    if(even == true)
    even = false;
    else 
    even = true;

    }
    } }}
      

  3.   

    import java.io.*;
    public class Test{
    public static void main(String args[]) throws Exception{
    System.out.print("Please input a number:");
    BufferedReader br1=new BufferedReader(new InputStreamReader(System.in));
    int length=Integer.parseInt(br1.readLine());
    for(int i=0;i<length;i++){
    if(i%2==0){
    for(int j=0;j<length;j++){
    System.out.print((i*length+j+1)+" ");
    }
    System.out.println("");
    }
    else{
    for(int j=0;j<length;j++){
    System.out.print(((i+1)*length-j)+" ");
    }
    System.out.println("");
    }
    }
    }
    }
      

  4.   

    class Table{
    int num=0;
    int t[][]=null;
    public void setNum(int i){
    this.num=i;
    }
    public int getNum(){
    return num;
    }
    public void setT(){
    t=new int[num][num];
    for(int i=0;i<num;i++){
    for(int j=0;j<num;j++){
    if(i%2==0)
    t[i][j]=i*num+j+1;
    else t[i][j]=(i+1)*num-j;
    }
    }
    }
    public void printT(){
    for(int i=0;i<num;i++){
    for(int j=0;j<num;j++){
    System.out.print(t[i][j]+"   ");
    }
    System.out.println();
    }
    }
    }
    public class Test {
    public static void main(String[] args) {
    Table table=new Table();
    table.setNum(5);
    table.setT();
    table.printT();
    }
    }
      

  5.   

    public class number
    {
    public static void main(String[] args)
    {
    int n,i,j;
    String str;
    int a[];
    System.out.println("Input N :");
    BuffereReader br=new BuffereReader(new InputstracReader(System.in));
    str=br.readLine();
    n=Integer.parseInt(str);
    for(i=1;i<=n*n;i++)
    {
    a[]=new a[n];
    a[i]=i+1;
    System.out.print(a[i]);
    if(i%n==0)
    System.out.println();
    }
    }
    }
    程序大概没错。就是InputstracReader()方法你再查查。我记得不是太清楚。
      

  6.   

    有个规律:
    奇数行: row*len + col + 1
    偶数行:(row+1) - col
      

  7.   

    说错了,
    是楼上的楼上不过,楼上兄弟的程序太疯狂
    for里面的东东,太夸张了吧
    --------------
    a[]=new a[n];//n值固定
    a[i]=i+1;//i的值 i<n*n
    -------------
      

  8.   

    试试这个
    public class a{

    public static void aa(int n){
         for(int i=1;i<=n;i++)
                    for(int j=1;j<=n;j++){
                     if(i%2==1){ System.out.print((i-1)*n+j); if(j==n) System.out.println();}
                     else      { System.out.print(i*n-j+1);   if(j==n) System.out.println();}
           }
    }

    public static void main(String[] args){
     aa(4);

    }
    }
      

  9.   

    mahb520(玉狐) 的程序实在是写得哼哼哈嘻......... -_-|||
      

  10.   

    /*
     * 创建日期 2005-9-29
     *
     * TODO 要更改此生成的文件的模板,请转至
     * 窗口 - 首选项 - Java - 代码样式 - 代码模板
     */
    package yhf;/**
     * @author hf.Yao
     *
     * TODO 要更改此生成的类型注释的模板,请转至
     * 窗口 - 首选项 - Java - 代码样式 - 代码模板
     */
    public class SnakeRank {

    public static void display(int n){

    for(int i = 0; i < n; i++){

    if(i%2 != 0){
    for(int j = n; j > 0; j--){
    System.out.print(i*n+j+" ");
    }
    System.out.println("\n");

    }else{
    for(int k = 1; k < n+1; k++){
    System.out.print(i*n+k+" ");
    }
    System.out.println("\n");
    }
    }

    } public static void main(String[] args) {
    display(9);
    }
    }测试结果
    1 2 3 4 5 6 7 8 9 18 17 16 15 14 13 12 11 10 19 20 21 22 23 24 25 26 27 36 35 34 33 32 31 30 29 28 37 38 39 40 41 42 43 44 45 54 53 52 51 50 49 48 47 46