Java

課題

ちょっと難しくなったかな。 プリミティブ型を使うとは…… public class Test { public static void main(String[] args) throws Exception { kata(new Double(10.0)); kata(new Integer(10)); kata("10"); kata(new Long(10)); } public static void kata(Ob…

課題

今回は前回のがわかっていれば簡単すぎるかな。 というか、ほとんど変わってない。 public class Test { public static void main(String[] args) throws Exception { System.out.println(add(10.0,20.0,30)); System.out.println(add("10.0","20","30")); S…

解答編

01:public class Test { 02: 03: public static void main(String[] args) throws Exception { 04: System.out.println(add(10.0,20.0)); 05: System.out.println(add("10.0","20")); 06: System.out.println(add(10,20)); 07: System.out.println(add(10,20…

課題(メソッドのオーバロードその2)

public class Test { public static void main(String[] args) throws Exception { System.out.println(add(10.0,20.0)); System.out.println(add("10.0","20")); System.out.println(add(10,20)); System.out.println(add(10,20.0)); System.out.println(ad…

課題(メソッドのオーバロード)

(for id:yurli) public class Test { public static void main(String[] args) throws Exception { kata("10"); kata(10); kata(10.0); } public static void kata(int args) { System.out.println("引数の型はint型です。"); System.out.println(args); } p…

課題

public class Test { public static void main(String[] args) throws Exception { //1 int ans; //2 ans = pow(5); //3,7 System.out.println(ans); //8 System.out.println(pow(6)); //9,13 System.out.println(pow(pow(4))); //14,18,22 } //23 private s…

課題

まず、昨日書いたプログラムの実行順を追ってみようと思う。 public class Test { public static void main(String[] args) throws Exception { //1 todayIs("晴天なり"); //2 todayIs("曇天なり"); //6 todayIs("吹雪なり"); //10 } //14 private static vo…

メソッド

昨日のプログラムに実行順序を念のために書いておく。 public class Test { public static void main(String[] args) throws Exception { //1 System.out.println("mainメソッドスタート"); //2 method(); //3 System.out.println("mainメソッド終了"); //7 …

メソッドです。

(for id:yurli) 結果を予想したあとに打ち込み実行して予想と実行結果を比べてみましょう。 public class Test { public static void main(String[] args) throws Exception { System.out.println("mainメソッドスタート"); method(); System.out.println("m…

今日の課題

昨日のを更に拡張して下記文字列が出力されるようにしましょう。 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 3 6 9 12 15 18 21 24 27 30 33 36 39 42 45 48 51 54 57 60 4 8 12 16 20 2…

今日の課題

(for id:yurli) for文をネストさせて九九の表を作りなさい。 一応出力イメージ 1 2 3 4 5 6 7 8 9 2 4 6 8 10 12 14 16 18 3 6 9 12 15 18 21 24 27 4 8 12 16 20 24 28 32 36 5 10 15 20 25 30 35 40 45 6 12 18 24 30 36 42 48 54 7 14 21 28 35 42 49 56 …

今日の課題

(for id:yurli) public class Test { public static void main(String[] args) throws Exception { for (int i = 1; i <= 9; i++) { for (int j = 1; j <= 9; j++) { System.out.println(i + " × " + j + " = " + (i * j)); } } } }結果を予想してから打ち込…

ちょっとWebアプリケーションを……

MySQLのSQLとOracleのそれが混ざってきそうな予感もするが、MySQLを使ったWebアプリでも作ってみようかなと言う気になった。要するに、JSP+TOMCAT+MySQLな感じで作ろうと思う。 今回、Servetは作らずにJSPからDAOをnewするような感じで作っていこうと思う。…

本日読むプログラム

String.replaceAllの使い方 public class sample1 { public static void main(String[] args) throws Exception { String a = "a == b"; a = a.replaceAll("==","!="); System.out.println(a); } }replaseAll(String,String)はJ2SE1.4以降にあるメソッドです…

今日読むプログラム

String.substringメソッドの使い方。 public class sample1 { public static void main(String[] args) throws Exception { String a = "abcdef"; String b = a.substring(1,3); System.out.println(b); String c = a.substring(4); System.out.println(c); …

今日読むプログラム

(for id:yurli) public class sample1 { public static void main(String[] args) throws Exception { String a = "abc"; String b = a; a += b + 100 + 200; System.out.println(a); } } 最後に出力される文字列は何でしょう? 今日は、複合代入演算子なる…

閏年を求めるプログラム

public class sample1 { public static void main(String[] args) throws Exception { sample1 sample = new sample1(); String ans = sample.test6(2004); System.out.println(ans); ans = sample.test7(1900); System.out.println(ans); System.out.printl…

今日の課題……

(for id:yurli) テーマ……オブジェクト指向についての訳のわからないたとえ話。どんなたとえ話にしようか……。……いいアイディアなし。そのまえに、用語について簡単に説明したいと思う。 クラス……データとメソッドがひとかたまりになったもの。 メソッド……ある…

文字列119999922 文字列212200111 はてな JAVAでソートするプログラムを教えてください。-------file.txt------10001021 文字列119999922 文字列212200111 TAB&・・

ファイルが1GBもあるからすべてを読んだらメモリーが足りなくなることは必須。 なので、普通にバブルソートとかクイックソートとかは使えません。 一定区間ごと分割してソートしてその区間を毎回変えてあげることによってできそうな気もします。でも、なかな…

練習問題のつっこみ

public class yurli { public static void main(String[] args) { int x = 6 ; int y = 3 ; //この時点でx = 6,y = 3 double z = 5.2 ; System.out.println(x / y ); x = (int)z ; //この時点でz = 5.2,x = 5 System.out.println(x / y); // 5/3 = 1.6666………

さらに、do-while文で書き直す

private void test1() throws Exception { try { InputStreamReader is = new InputStreamReader(System.in); BufferedReader br = new BufferedReader(is); Random rnd = new Random(); int target = rnd.nextInt(101); int ges = 0; do { System.out.print…

答え……(for id:yurli)

今日のサンプル

(for id:yurli) public class sample1 { public static void main(String[] args) throws Exception { int[] i = new int[10]; //while文を使ってデータを挿入 int j = 0; while (j < 10) { i[j] = j * 2; j++; } int total = 0; j = 0; //while文を使って配…

更にサンプル

public class sample1 { public static void main(String[] args) throws Exception { int[] i = new int[10]; //for文を使ってデータを挿入 for (int j = 0; j < 10; j++) { i[j] = j * 2; } int total = 0; //for文を使って配列に入っている値の和を求めま…

Javaサンプル。

(for id:yurli) import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.Random; /* * 作成日: 2005/08/28 * * TODO この生成されたファイルのテンプレートを変更するには次へジャンプ: * ウィン…