Lesson6の練習4の改変

class Example4 {
  public static void main(String[] args){
    String str1="<------------+------------>";
    String str2="             |             ";
    int center=str1.indexOf("+");
    int width=center-1;
    int row=15;
    double x0=0,x1=2*Math.PI;

    for(int i=0;i<row;i++){
      double x=i*(x1-x0)/row+x0;
      double y=Math.sin(x);
      int p=(int)(y*width)+center;
      String str;
      if(i==0){
        str=str1.substring(0,p)+"*"+str1.substring(p+1);
      }
      else{
        str=str2.substring(0,p)+"*"+str2.substring(p+1);
      }
      System.out.println(str);
    }
  }
}

Javaセミナー2014-20141216?


トップ   新規 一覧 単語検索 最終更新   ヘルプ   最終更新のRSS