[Power Java Compact] 2장 연습문제

2021. 12. 13. 17:54·Major/Java
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
'Major/Java' 카테고리의 다른 글
  • [Java] 문자열 안에서 단어찾기
  • [Power Java Compact] 3장 연습문제
  • [Power Java Compact] 1장 연습문제
  • Power java 2판 - Chapter 2 exercise
BeNI
BeNI
코딩하는 블로그
  • BeNI
    코딩못하는컴공
    BeNI
  • 전체
    오늘
    어제
    • Menu (254)
      • My profile (1)
      • 회고 | 후기 (8)
      • Frontend (66)
        • Article (11)
        • Study (36)
        • 프로그래머스 FE 데브코스 (19)
      • Backend (0)
      • Algorithm (58)
        • Solution (46)
        • Study (12)
      • Major (111)
        • C&C++ (23)
        • Java (20)
        • Data Structure (14)
        • Computer Network (12)
        • Database (15)
        • Linux (6)
        • Architecture (3)
        • Lisp (15)
        • OS (1)
        • Security (2)
      • etc (2)
  • 링크

    • 깃허브
    • 방명록
  • 인기 글

  • 최근 댓글

  • 최근 글

  • 태그

    lisp
    리팩토링
    자료구조
    백준
    C++
    파일처리
    Algorithm
    데브코스
    프로그래머스
    react
  • hELLO· Designed By정상우.v4.10.2
BeNI
[Power Java Compact] 2장 연습문제
상단으로

티스토리툴바