목차
1. Hello world! 출력하기
2. 변수의 선언
3. 과제
4. 과제결과&의문점
1. Hello world! 출력하기
class Ex01{
public static void main(String[] args)
{
System.out.println("Hello world!");
}
}
2. 변수의 선언
class Ex04{
public static void main(String[] args)
{
char su1; //변수의 선언
su1='A'; //변수의 초기화
//float su1 su1=3.14F; 무조건 F만 입력
//long su1 su1=1234L; 무조건 L만 입력
//문자열은 2개사용, char는 1개사용
//char에서 su1=''; 이렇게만 두는 건 오류.
System.out.println(su1+1);
/////////////절개선////////////////
char su1;
su1=67;
System.out.println(su1);
}
}
3. 과제
비트편의점
--------------------------------------
상품 | 갯수 | 가격 | 계
--------------------------------------
생수 3 900 2700
꼬깔콘 2 1200 2400
커피 4 300 1200
아이스크림 1 2500 2500
--------------------------------------
합계 000000
--------------------------------------
위의 영수증을 출력하라
4.과제결과 & 의문점
<내 코드>-다음 강의 때 수정될 예정
class homework
{
public static void main(String[] args)
{
System.out.println("비트편의점");
System.out.println("--------------------------------------");
System.out.println("상품\t|\t갯수 |\t가격 |\t 계");
System.out.println("--------------------------------------");
String a,b,c,d = new String(); //상품
a="생수";
b="꼬깔콘";
c="커피";
d="아이스크림";
int e,f,g,h = 0; //갯수
e = 3;
f = 2;
g = 4;
h = 1;
int i,j,k,l = 0; //가격
i = 900;
j = 1200;
k = 300;
l = 2500;
System.out.println(a + "\t\t"+e+"\t" + i + "\t"+ e*i);
System.out.println(b + "\t\t"+f+"\t" + j + "\t" + f*j);
System.out.println(c + "\t\t"+g+"\t" + k + "\t" + g*k);
System.out.println(d + "\t"+h+"\t" + l +"\t"+ h*l);
System.out.println("--------------------------------------");
System.out.print("\t\t합계\t\t");
System.out.println(e*i+f*j+g*k+h*l);
//("\t\t합계\t\t"+e*i+f*j+g*k+h*l); //괄호안치니까 결과값이 다르게 나옴. 결과값: 27002400120025008800
System.out.println("--------------------------------------");
}
}
'코딩 > 자바 기초특강' 카테고리의 다른 글
20.11.06 FRI 자바기초특강 5 (0) | 2020.11.06 |
---|---|
20.11.05 THU 자바 기초특강 (0) | 2020.11.05 |
20.11.04 WED 3일차 과제 --11.05 THU 과제 피드백 (0) | 2020.11.04 |
20.11.04 WED 자바 기초특강 3 (0) | 2020.11.04 |
20.11.03 TUE 자바 기초특강 2 (0) | 2020.11.03 |
댓글