このブログを検索

2019年4月5日金曜日

久しぶりの投稿 (あきらめました Ruby)

今、手元にあるプログラミングの参考書は、
「やさしいJava」(著者 高橋麻奈)
Ruby 諦めました。

Javaを勉強中。
だって、Rubyより文法がしっかりしていて、
丸覚えしやすいんだもん。。。
(ただし、記述量が3倍だ)

⭐️今日作ったプログラム。(とりあえずのFizzBuzz)

class Sample
{
    public static void main(String[] args)
    {
        System.out.println("100までのFizzBuzzを開始します。");
        int score = 0; // 合計用
        
        for(int i=0; i<=9; i++) {
            for(int j=1; j<=10; j++) {
                score = (i*10)+j;
                if((score % 3)==0 && (score % 5) == 0) {
                    System.out.print("FizBuz" + "\t");
                }
                else if((score % 3) == 0) {
                    System.out.print("Fizz" + "\t");
                }
                else if((score % 5) == 0) {
                    System.out.print("Buzz" + "\t");
                }
                else {
                    System.out.print(score + "\t");
                }
                
            }
            System.out.print("\n");
        }
    }
}

今日の教訓
 まるっきり 諦めなければそれで良し。

0 件のコメント:

コメントを投稿