AP102 2016/6/27 JAVA 第一堂
public class MainClass
{
public static void main(String[] argv)
{
byte b = 1;
short s = 2;
int i = 3;
long l = 4;
float f = 1.1f;
double d = 1.2;
boolean bool = true;
char c = 'a';
String text = "hello world";
System.out.println("b = " + b + "\ns = " + s);
}
}
強制轉型
class Casting{
public static void main(String[] args){
int i = 1;
double d = 11.1;
double sum1 = i + d;
int sum2 = (int)(i + d);
System.out.println(sum1);
System.out.println(sum2);
}
}
數字與字串串接
class ConcatenateOP{
public static void main(String[] args){
String str1 = "123";
String str2 = str1 + 10;
int i = 123;
double d = 3.12;
System.out.println(str2);
System.out.println(i + d);
System.out.println(i + " " + d);
System.out.println("i = " + i + ", d = " + d);
}
}
結果
12310
126.12
123 3.12
i = 123, d = 3.12
Comments
Post a Comment