从Java教科书中绘制图形

菲利普斯

我正在研究Reges,Stuart和Martin Stepp的第2章“自检问题”。构建Java程序:“回归基础”方法。我正在尝试使输出低于我的代码。我试图找出line!\/关系和数学需要计算for loops这不是作业,我也不需要答案,方向或指导。

!!!!!!!!!!!!!!!!!!!!!!
\\!!!!!!!!!!!!!!!!!!//
\\\\!!!!!!!!!!!!!!////
\\\\\\!!!!!!!!!!//////
\\\\\\\\!!!!!!////////
\\\\\\\\\\!!//////////

到目前为止,我的代码是:

/**
 * Created on 8/28/15.
 * Following Reges, Stuart, and Martin Stepp. Building Java Programs: A Back to Basics Approach.
 * Chapter 2 Self-Check Problems
 */
public class Ch2_SelfCheckProblems {
    public static void main(String[] args) {
        question34();

    }

    public static void  question34(){
/**
* Table
* Line 1   ! = 22  \ = 0   / = 0
* Line 2   ! = 18  \ = 2   / = 2
* Line 3   ! = 14  \ = 4   / = 4
* Line 4   ! = 10  \ = 6   / = 6
* Line 5   ! = 6   \ = 8   / = 8
* Line 6   ! = 2   \ = 10  / = 10
*/

        for (int line = 1; line <= 6; line++){
            for (int i = 1; i <= 22; i++){
//                for (int j = 1; j <= (line - 1); j++){
//                    System.out.print("\");
//                }
                System.out.print("!");
            }
            System.out.println();
        }
    }



}
沃洛洛

试试这个:(我手边没有编译器)

for (int line = 1; line <= 6; line++){
  for(int i = 1; i<=line-1; i++) {
    System.out.print("\\");
  }
  for (int i = 1; i <= 22 - 4*(line-1); i++){
    System.out.print("!");
  }
  for(int i = 1; i<=line-1; i++) {
    System.out.print("//");
  }
  System.out.println();
}

如果您什么都不懂,请发表评论。他们全耳。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章