/*------------------- Ex8_2.java 文字列の操作メソッド --------------------*/ package jp_bunkyo; public class Ex8_2 { public static void main(String[] args) { char moji; String msg1 = "abcdefg"; String msg2 = "本日は晴天なり"; moji = msg1.charAt(0); System.out.println("moji = " + moji); moji = msg1.charAt(3); System.out.println("moji = " + moji); moji = msg2.charAt(1); System.out.println("moji = " + moji); moji = msg2.charAt(4); System.out.println("moji = " + moji); System.out.println("msg1 の長さは" + msg1.length() + ", msg2 の長さは" + msg2.length() + "だよ"); if ( msg1.length() > msg2.length() ) { System.out.println("msg1の方が文字数が多い"); } else { System.out.println("msg2の方が文字数が多い"); } } }