Head First Java(第2版)

一、基本概述

1、进入Java的世界

Java的工作方式

Java简史

Java的程序结构

剖析类


案例:数啤酒瓶

package com.jackson.java;
/**
 *
 * @版权 : Copyright (c) 2020-2021 Jacson个人学习代码
 * @author: Jackson
 * @E-mail: [email protected]
 * @创建日期: 2020年3月12日 下午7:51:53
 * @ClassName BeerSong
 */
public class BeerSong {
    public static void main(String[] args) {
        int beerNum = 99;
        String word = "bottles";
        while (beerNum > 0) {
            if (beerNum == 1) {
                word = "bottle";
            }
            System.out.println(beerNum + " " + word + " of beer on the wall");
            System.out.println(beerNum + " " + word + " of beer.");
            System.out.println("Take one down.");
            System.out.println("Pass it around.");
            beerNum = beerNum - 1;

            if (beerNum > 0) {
                System.out.println(beerNum + " " + word + " of beer on the wall");
            } else {
                System.out.println("No more bottles of beer of the wall.");
            }//else结束
            System.out.println();
        }//while循环结束
    }//main方法结束

}//class结束

输出结果如下:

案例:随机组合专家术语

package com.jackson.java;

/**
 *
 * @版权 : Copyright (c) 2020-2021 Jacson个人学习代码
 * @author: Jackson
 * @E-mail: [email protected]
 * @创建日期: 2020年3月12日 下午8:52:26
 * @ClassName PhraseOMatic
 */
public class PhraseOMatic {
    public static void main(String[] args) {
        String[] wordListOne = { "24/7", "multi-Tier", "30000 foot", "B-to-B", "web-based" };
        String[] wordListTwo = { "empowered", "sticky", "value-added", "oriented", "focused", "share", "dynamic" };
        String[] wordListThree = { "process", "tipping-point", "solution", "architecture", "mission" };
//      计算每一组有多少个名词术语
        int oneLength = wordListOne.length;
        int twoLength = wordListTwo.length;
        int threeLength = wordListThree.length;
//      产生随机数字
        int randOne = (int) (Math.random() * oneLength);
        int randTwo = (int) (Math.random() * twoLength);
        int randThree = (int) (Math.random() * threeLength);
//      组合出专家术语
        String phrase = wordListOne[randOne] + " " + wordListTwo[randTwo] + " " + wordListThree[randThree];
        System.out.println("What we need is :" + phrase);

    }

}
//输出结果:What we need is :web-based empowered process

2、类与对象

猜你喜欢

转载自www.cnblogs.com/jacksonwzx/p/12469631.html