728x90
Chapter 02 자바 프로그래밍 기초
Mini Project
public class FtoC {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("화씨 온도를 입력하시오: ");
double f = sc.nextDouble();
double c = (f-32)*5/9; //5/9를 먼저 곱하면 0이된다.
System.out.println("섭씨온도는 "+c);
}
}
Exercise
1.
byte short int long float double char boolean
2.
String
3.
int
4.
ⓒ
5.
변수 : k, m, f
상수 : size
6.
1) 11, 0
2) 11, 1
7.
100200
300
100200
하나라도 문자열이면 문자열로 계산안된다.
8.
10209
9.
0
10.
!
11.
==
12.
abcghidef
13.
0
14.
++i나 i++나 결국에는 i값이 1 증가하는 것이므로 출력할 때는 6이 출력되게 된다.
15.
x | a | b | c | |
5 | 0 | |||
8 | 2 | |||
9 | 3 | |||
10 | 3 | 1 | 0 | 1 |
11 | 3 | 1 | 0 | 1 |
Programming Exercise
1.
import java.util.Scanner;
public class quiz {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("오렌지의 개수를 입력하시오: ");
int num = sc.nextInt();
System.out.printf("%d박스가 필요하고 %d개가 남습니다. ", num/10, num%10);
}
}
2.
import java.util.Scanner;
public class quiz {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("마일을 입력하시오: ");
double num = sc.nextDouble();
System.out.printf("%.1f마일은 %.2f킬로미터입니다. ", num, num*1.609);
}
}
3.
import java.util.Scanner;
public class quiz {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("받은돈 : ");
int num = sc.nextInt();
System.out.print("상품 가격 : ");
int num1 = sc.nextInt();
System.out.println("부가세: "+ num1/10);
System.out.printf("잔돈: %d ", num-num1);
}
}
4.
import java.util.Scanner;
public class quiz {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("구의 반지름: ");
double num = sc.nextDouble();
double c = num*num*num*4/3;
System.out.printf("구의 부피: " + c );
}
}
5.
import java.util.Scanner;
public class quiz {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("정수: ");
int num = sc.nextInt();
int n = num;
String ans = "";
while(true) {
if(n ==0) break;
ans+=Integer.toString(n%2);
n/=2;
}
StringBuffer str = new StringBuffer(ans);
System.out.print(num+": "+str.reverse());
}
}
728x90
'Major > Java' 카테고리의 다른 글
[Power Java Compact] 4장 연습문제 (3) | 2021.12.20 |
---|---|
[Java] 문자열 안에서 단어찾기 (0) | 2021.12.20 |
[Power Java Compact] 3장 연습문제 (0) | 2021.12.15 |
[Power Java Compact] 1장 연습문제 (0) | 2021.12.13 |
Power java 2판 - Chapter 2 exercise (0) | 2021.03.14 |