Java/2012.04 강좌
2일차 변수
Bohemian life
2012. 4. 5. 10:30
public class IntStudy { public static void main(String[] args) { //78954+12345 =? //78954+55444 =? //78954+11345 =? //100번 물어본다면? System.out.println("1+2=3"); System.out.println(78954+12345); int a=78954; //메모리에 78954 값을 저장 //int a 변수의 선언, a=78954 변수의 초기화 //변수 선언 초기화 하세요~ int b; //b라는 변수 선언 b=12345; //b변수 초기화 int c=99955; System.out.println(a+b); //인간적인 System.out.println(a+" 더하기 "+b+" 는 "+(a+b)); //덜인간적인 언어 C처럼 System.out.printf("%d 더하기 %d 는 %d \n",a,b,a+b); System.out.println(a+" 더하기 "+c+" 는 "+(a+c)); // \n 한줄 띄기 "나 \n 너 \n" int d=5,e=6,f=7,g=8,h=9;//변수 선언 및 초기화 int i,j,k,l,m,n; //변수 선언 i=10;j=11; //변수값에 값을 초기화(initialize) /*int z=100; //int z=50; error z=2147483647;*/ //실수 타입 float,double double pi=3.141592; float zi=3.141592f; int r=5;//반지름 double area;//면적, 변수 선언 area = r*r*pi; System.out.print("반지름이" +r+"인 원의 면적은 " +area+"이다"); } }
public class Test { public static void main(String[] args){ /*float a=33.33f; float b=55.2f; float c=a*b; float d=33.33f; float e=8.8f; float f=d*e; System.out.println("가로 "+a+"*"+"세로"+b+"의 직사각형의 넓이는 "+c+"입니다."); System.out.println("가로 "+d+"*"+"세로"+e+"의 직사각형의 넓이는 "+f+"입니다."); */ float aa=33.33f; float bb=55.2f; float cc=8.8f; String exp="의 직사각형의 넓이는"; System.out.print("가로"+aa+" * " +"세로"+bb+exp+aa*bb+"입니다.\n"); System.out.print("가로"+aa+" * " +"세로"+cc+exp+aa*cc+"입니다.\n"); String hi = "안녕하세요"; char hello='하'; boolean IamGirl=false; boolean IamMan=true; } }