在java中打印1到10,不带任何循环

在java中打印1到10,不带任何循环,java,Java,可能重复: 面试问题: 在java中不使用任何循环打印1到10。简单方法:System.out.println值: System.out.println(1); System.out.println(2); System.out.println(3); System.out.println(4); System.out.println(5); System.out.println(6); System.out.println(7);

可能重复:

面试问题:


在java中不使用任何循环打印1到10。

简单方法:
System.out.println
值:

    System.out.println(1);
    System.out.println(2);
    System.out.println(3);
    System.out.println(4);
    System.out.println(5);
    System.out.println(6);
    System.out.println(7);
    System.out.println(8);
    System.out.println(9);
    System.out.println(10);
复杂方式:使用递归

public void recursiveMe(int n) {
    if(n <= 10) {// 10 is the max limit
        System.out.println(n);//print n
        recursiveMe(n+1);//call recursiveMe with n=n+1
    }
}
recursiveMe(1); // call the function with 1.
public void recursiveMe(int n){

如果(n如果你喜欢你的程序迟钝,没有循环,没有条件语句或main方法

static int i = 0;
static {
    try {
        recurse();
    } catch (Throwable t) {
        System.exit(0);
    }
}

private static void recurse() {
    System.out.print(++i + 0 / (i - 11) + " ");
    recurse();
}

这使用了一个循环,但可能是一个有趣的答案

Random random = new Random(-6732303926L);
for(int i = 0; i < 10; i++)
    System.out.print((1+random.nextInt(10))+" ");
}
Random Random=新随机(-6732303926L);
对于(int i=0;i<10;i++)
System.out.print((1+random.nextInt(10))+“”);
}

你可以将其重新构造为不使用循环。

你是如何在26秒内完成这项工作的?因为Eclipse!!!:p我喜欢Eclipse。@HarryJoy:你的Eclipse似乎是以光速运行的…:先写syso,然后按ctrl+space。然后按alt+down复制。然后在某个地方键入recursiveMe,然后按ctrl+space。然后写下和if条件和syso。面试问题:你的答案是什么?你是在手机上输入这个问题,希望在面试官回来之前得到答案吗?