解答・コメントを送る方法

コメントを送るには2つの方法があります。
  • 匿名でコメントを書く
    ログインせずにコメントを書くことができます。 名前は「匿名」となります。
  • アカウントを作成してコメントを書く
    アカウントを作成すると、記名での投稿ができます。 また、プロフィールページが作成され、 簡単なプロフィールや 統計情報が表示されるようになります。
どちらの場合も投稿後の修正・削除はできないので、 投稿前によくご確認下さい。

投稿ボタンを押す前に以下の文章を確認してください

  • 当サイトへの投稿は クリエイティブ・コモンズ・ライセンス BY(表示)および、その解釈に同意するものとみなされます。各ページには下のようにライセンス表示が行われます。
    Creative Commons License このサイトの内容は、 クリエイティブ・コモンズ・ライセンスの下でライセンスされています。 [詳細]
  • あなたの投稿したコード・コメント・トピックが再利用・添削されることを望まない場合は、投稿をお控えください。
  • 自分が書いていない、ウェブサイトや書籍などからの無断コピーは著作権の侵害です。著作権者の了解を得るか、自分で0から書いてください。
  • 著作権の侵害、名誉毀損、など投稿内容に問題がある場合、削除することがあります。
  • これらのことにあなたはあらかじめ同意したものとみなされます。

Post comment

Post a comment to the following challenge: 設定ファイルから値を取得 (Nested Flatten)

As a reply to the following comment: horiuchi: この頃、自分で書く時はこんな形にしてます...(#6605) [show]

[hide]

この頃、自分で書く時はこんな形にしてます。

設定ファイルの内容は

ファイル:ShowPrice.properties

>>

item.name=apple

item.cost=200

<<

ファイル:ShowPrice2.properties

>>

item.name=orange

item.cost=100

<<

ファイル:ShowPrice3.properties

>>

<<

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.Reader;
import java.util.Properties;


public class Sample186 {
    private static final Properties defaultProperties_ = new Properties();
    static {
        defaultProperties_.setProperty("item.name", "nothing");
        defaultProperties_.setProperty("item.cost", "0");
    }


    private final Properties properties_ = new Properties(defaultProperties_);

    public Sample186(InputStream stream) throws IOException {
        properties_.load(stream);
    }
    public Sample186(Reader reader) throws IOException {
        properties_.load(reader);
    }

    public String get(String key) {
        return properties_.getProperty(key);
    }
    public int getInteger(String key) {
        try {
            return Integer.parseInt(get(key));
        } catch (NumberFormatException ex) {
            ex.printStackTrace();
            return 0;
        }
    }
    public long getLong(String key) {
        try {
            return Long.parseLong(get(key));
        } catch (NumberFormatException ex) {
            ex.printStackTrace();
            return 0L;
        }
    }
    public double getDouble(String key) {
        try {
            return Double.parseDouble(get(key));
        } catch (NumberFormatException ex) {
            ex.printStackTrace();
            return 0.0;
        }
    }


    public static void main(String[] args) {
        try {
            Sample186 apple = new Sample186(new FileInputStream("ShowPrice.properties"));
            System.out.println(getPrice(apple));
            Sample186 orange = new Sample186(new FileInputStream("ShowPrice2.properties"));
            System.out.println(getPrice(orange));
            Sample186 nothing = new Sample186(new FileInputStream("ShowPrice3.properties"));
            System.out.println(getPrice(nothing));
        } catch (IOException ex) {
            ex.printStackTrace();
        }
    }
    private static String getPrice(Sample186 sample186) {
        return String.format("「%s」は%d円(税込み)", sample186.get("item.name"), (int)(sample186.getInteger("item.cost") * 1.05));
    }
}


コメント本文
形式 [?]
コード
言語

タグ
半角スペースで区切って複数のタグを入力できます。
参考ページタイトル

参考ページURL
利用規約を読んで同意する必要があります。
by guest

Index

Feed

Other

Link

Pathtraq

loading...