- mainメソッドの先頭からプログラムの実行がはじまる
- 文は処理の小さな単位となる
- ブロックはいくつかの文からなる
- Javaのコードは1つ以上のクラスからなる
- コメントとしてコード中にメモを書ける
- リテラルには文字 文字列 数値などがある
- 文字リテラルは''でくくる
- 特殊な文字はエスケープシーケンスであらわす
- 文字列リテラルは""でくくる
- 整数リテラルは8進数や16進数であらわすこともできる
Last active
December 27, 2015 08:49
-
-
Save shigemk2/7299323 to your computer and use it in GitHub Desktop.
やさしいJava 第5版 2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Sample1 | |
{ | |
public static void main(String[] args) | |
{ | |
System.out.println("ようこそJavaへ!"); | |
System.out.println("Javaを始めましょう!"); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// mainメソッドからプログラムの処理が始まる | |
// Javaのコードはclassという言葉が先頭についたブロックが必要 | |
class Sample2 | |
{ | |
public static void main(String[] args) | |
{ | |
System.out.print("ようこそJavaへ!"); | |
System.out.print("Javaを始めましょう!"); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Sample3 | |
{ | |
public static void main(String[] args) | |
{ | |
System.out.println('A'); | |
System.out.println("ようこそJavaへ!"); | |
System.out.println(123); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Sample4 | |
{ | |
public static void main(String[] args) | |
{ | |
System.out.println("円記号を表示する:¥"); | |
System.out.println("アポストロフィを表示する:\'"); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Sample5 | |
{ | |
public static void main(String[] args) | |
{ | |
System.out.println("8進数101の文字は\101です"); | |
System.out.println("16進数0061の文字は\u0061です"); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Sample6 | |
{ | |
public static void main(String[] args) | |
{ | |
System.out.println("10進数の10は" + 10 + "です"); | |
System.out.println("8進数の10は" + 010 + "です"); | |
System.out.println("16進数の10は" + 0x10 + "です"); | |
System.out.println("16進数のFは" + 0xF + "です"); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class SampleP1{public static | |
void main (String[] args) | |
{System.out.println("ようこそJavaへ!"); | |
System.out.println("Javaをはじめましょう!"); } } | |
// class SampleP1 { | |
// public static void main (String[] args) | |
// { | |
// System.out.println("ようこそJavaへ!"); | |
// System.out.println("Javaをはじめましょう!"); | |
// } | |
// } | |
// 文法的に間違っちゃないが読みづらい |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class SampleP2 { | |
public static void main (String[] args) | |
{ | |
// 文字と数値を入力する | |
System.out.println('A'); | |
System.out.println("ようこそJavaへ!"); | |
System.out.println(123); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class SampleP3 { | |
public static void main (String[] args) | |
{ | |
// 文字と数値を入力する | |
System.out.println(123); | |
System.out.println("¥100もらった"); | |
System.out.println("またあした"); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class SampleP4 { | |
public static void main (String[] args) | |
{ | |
// 文字と数値を入力する | |
System.out.println("1\t2\t3"); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class SampleP5 { | |
public static void main (String[] args) | |
{ | |
// 文字と数値を入力する | |
System.out.println("8進数"); | |
System.out.println(006); | |
System.out.println(024); | |
System.out.println(015); | |
System.out.println("16進数"); | |
System.out.println(0x06); | |
System.out.println(0x14); | |
System.out.println(0x0D); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment