STUDY/ JAVA
자바 프로그래밍 Chapter04 실습문제
Hongfluenza
2018. 4. 17. 00:58
1.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | class TV { String name; int year; int inch; public TV(String name, int year, int inch){ this.name=name; this.year=year; this.inch=inch; } void show() { System.out.println(name+"에서 만든 "+year+"년형 "+inch+"인치 TV"); } } public class _01 { public static void main(String[] args) { TV myTV = new TV("LG",2017,32); myTV.show(); } } | cs |
2.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | import java.util.Scanner; public class Grade { private int math, science, english; public Grade(int math, int science, int english) { this.math=math; this.science=science; this.english=english; } int average() { return (math+science+english)/3; } public static void main(String[] args) { Scanner scanner = new Scanner(System.in); System.out.print("수학, 과학, 영어 순으로 3개의 점수 입력>>"); int math = scanner.nextInt(); int science = scanner.nextInt(); int english = scanner.nextInt(); Grade me = new Grade(math, science, english); System.out.println("평균은 "+me.average()); scanner.close(); } } | cs |
3.

| public class Song { String title,artist,country; int year; public Song(int year, String country, String artist, String title){ this.year=year;this.country=country;this.artist=artist;this.title=title; } void show() { System.out.println(year+"년 "+country+"국적의 "+artist+"가 부른 "+title); } public static void main(String[] args) { Song song = new Song(1978,"스웨덴","ABBA","Dancing Queen"); song.show(); } } | cs |
4.