java - 在所需的输出中查找模式

标签 java

这对某些人来说可能是非常基本的,但我似乎无法理解它。我的作业方向是:

Only one place should be changed. Instead of printing

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

make it print:

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);
    }
}

最佳答案

图案比计数器的平方小一(逆序)

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);
    }
}

关于java - 在所需的输出中查找模式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35561619/

相关文章:

java - 尝试使用 UTF-16 字符代码打印 "white smiling face"\u263A

java - 捕获由特殊字符嵌套/包围的正则表达式组

java - 在 android VideoView 上播放之前下载视频

用于存储过程的 Java 流

java - 如何使用 Java 中的 API Update(版本 5)更新 ElasticSearch 中的 HashMap 数据?

java - 如何将值集合绑定(bind)到 jOOQ 批量插入

java - 使用 BinaryTree 将字符编码为二进制

带有 JS 的 Java 自定义标签

java - 多次重复使用同一页面

java - 通过验证解析日期