Skip to content

Instantly share code, notes, and snippets.

@amippy
Last active February 28, 2016 15:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save amippy/438d14c89f38134c8109 to your computer and use it in GitHub Desktop.
Save amippy/438d14c89f38134c8109 to your computer and use it in GitHub Desktop.
文系大学生のJava入門 ref: http://qiita.com/amippy/items/96e8e725382881b6c9f3
1 public class HelloWorld{
2 public static void main(String[] args){
3 System.out.println("MuscleWorld!");
4 }
5}
1 public class HelloWorld{
2 public static void main(String[] args){
3 int age;
4 age = 21;
5 System.out.println(age);
6 }
7 }
1 public class HelloWorld{
2 public static void main(String[] args){
3 final int AGE = 21;
4 System.out.println("私の年齢は"+AGE+"です!");
5 }
6 }
1 public class HelloWorld{
2 public static void main(String[] args){
3 final int AGE = 21;
4 System.out.println("私の年齢は"+AGE+"です!");
5 AGE = 18;
6 System.out.println("私は"+AGE+"歳に戻りたいです。");
5 }
6 }
整数
int : 普通の整数     int age = 20; /*利用頻度が高い*/
long: 大きな整数
short:小さな整数
byte:shortよりさらに小さな整数
整数
int : 普通の整数     int age = 20; /*利用頻度が高い*/
long: 大きな整数
short:小さな整数
byte:shortよりさらに小さな整数
少数
double: 普通の少数       /*特別な事情がない限りdoubleを使う*/  
float: 少し曖昧でも良い少数
少数
double: 普通の少数       /*特別な事情がない限りdoubleを使う*/  
float: 少し曖昧でも良い少数
真偽値
boolean: trueかfalse    boolean result = true;  /*結果は成功という意味*/
真偽値
boolean: trueかfalse    boolean result = true;  /*結果は成功という意味*/
文字
char : 一文字 「''」で表現 char gender; = '女'
文字
char : 一文字 「''」で表現 char gender; = '女'
文字列
String : 文字の並び 「""」で表現  String name; = "筋トレ"
文字列
String : 文字の並び 「""」で表現  String name; = "筋トレ"
変数の初期化
型 変数名 = 代入するデータ;
1 public class HelloWorld{
2 public static void main(String[] args){
3 int age = 21;
4 System.out.println("私は"+age+"歳です!");
5 age = 22;
6 System.out.println("今年で"+age+"歳になります!");
7 }
8 }
【定数の宣言方法】
final 型 定数名(大文字) = データ;
1 public class HelloWorld{
2 public static void main(String[] args){
3 final int AGE = 21;
4 System.out.println("私の年齢は"+AGE+"です!");
5 AGE = 18;
6 System.out.println("私は"+AGE+"歳に戻りたいです。");
5 }
6 }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment