在期望的输出中找到模式

时间:2016-02-22 18:55:45

标签: java

这对某些人来说可能是非常基本的,但我似乎无法绕过它。我的任务指示是:<​​/ p>

  

只应更改一个地方。   而不是打印

1, 2, 3, 4, 5, 6, 7, 8, 9, 10
     

打印:

99, 80, 63, 48, 35, 24, 15, 8, 3, 0

代码:

public class Lab9
{
    public static void main(String args[])
    {
        int counter;
        counter=1; // do not change this line
        while(counter<=10) // do not change this line
        {
            System.out.println(counter); // do change this line
            counter=counter+1; // do not change this line
        }
        System.exit(0);
    }
}

2 个答案:

答案 0 :(得分:9)

模式比计数器的平方小一个(以相反的顺序)

public class Lab9{ 
    public static void main(String args[])
    {
        int counter;
        counter=1; // do not change this line
        while(counter<=10) // do not change this line
        {
            System.out.println((11-counter)*(11-counter)-1); // do change this line
            counter=counter+1; // do not change this line
        }
        System.exit(0);
    }
}

答案 1 :(得分:1)

我不知道这是不是你想要的,但我认为你必须找到这种模式。

您可以尝试这样的事情:

public class Lab9{
    public static void main(String args[]){
        int counter;
        counter=1; // do not change this line
        while(counter<=10) // do not change this line
        {
            System.out.println((12-counter)*(10-counter)); // changed
            counter=counter+1; // do not change this line
        }
        System.exit(0);
    }
}