⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 main.java

📁 java的经典例子
💻 JAVA
字号:
import java.util.Date;import java.util.Vector;import java.io.IOException;import java.io.DataInputStream;class Main {    private final static Vector monthVec = new Vector(12);    static {        String[] months = {            "Jan", "Feb", "Mar", "Apr", "May", "Jun",            "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};        for (int i = 0; i < months.length; i++)            monthVec.addElement(months[i]);    }    public static int readFromUser(String query, Vector map) {        System.out.print("Enter " + query + ": ");        System.out.flush();        try {            DataInputStream in = new DataInputStream(System.in);            String numStr = in.readLine();            return (map.indexOf(numStr));        } catch (IOException e) {        }        return (0);    }    public static int readFromUser(String query) {        System.out.print("Enter " + query + ": ");        System.out.flush();        try {            DataInputStream in = new DataInputStream(System.in);            String numStr = in.readLine();            return (Integer.parseInt(numStr));        } catch (IOException e) {            return (0);        } catch (NumberFormatException e) {            return (0);        }    }    private final static String[] fortunes = {        "There is good prospect in store for you",        "Don't travel aboard",        "A mysterious stranger is in your future"    };    public static String getFortune(Date d) {        // use birth date to determine fortune        int days = (int)(d.getTime()/(24*60*60*1000));        return (fortunes[days%fortunes.length]);    }    // Gets birth date from user and tells him his fortune    public static void FortuneTeller(Date bday) {        int year = readFromUser("Year");        if (year > 1900)            year -= 1900;        int month = readFromUser("Month", monthVec);        if (month < 0)            month = 0;  // ignore        int day = readFromUser("Day");        // Set birth date        bday.setYear(year);        bday.setMonth(month);        bday.setDate(day);        System.out.println("Your fortune is: " + getFortune(bday) + ".");    }    public static void main(String[] args) {        Date d = new Date();        while (true)            FortuneTeller(d);    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -