본문 바로가기

반응형

프로그래밍 공부/java

[JAVA] 정보를 입력 받아 BMI 지수를 계산하기(포매팅 사용) Q. 이름, 키, 몸무게를 입력받아 BMI 지수를 계산해 저장하는 프로그램을 만들어 보세요. public class Student { String name; double height; double weight; double bmi_num; public Student(String name, double height, double weight) { this.name=name; this.height=height; this.weight=weight; } public void bmi() { bmi_num = weight / ((height/100)*(height/100)); if (bmi_num == 0 || bmi_num 더보기
[JAVA] student 클래스의 멤버변수를 적절한 생성자를 이용해 초기화하기 Q. student 클래스의 멤버변수를 default 생성자가 아닌 적절한 생성자를 이용하여 초기화하는 프로그램을 만들어보세요. public class Student { String name; int age; double height; public Student(String name, int age, double height) { this.name = name; this.age = age; this.height = height; } } public class Student_1 { public static void main(String[] args) { Student stu = new Student("도토리", 33, 160.4); System.out.println("이름 : " + stu.name); S.. 더보기
[JAVA] student 클래스의 멤버 변수를 default 생성자를 이용하여 초기화하기 Q. student 클래스의 멤버 변수를 default 생성자를 이용하여 초기화하는 프로그램을 만들어보세요. public class Student_1 { public static void main(String[] args) { Student student = new Student(); System.out.println("이름 : " + student.name); System.out.println("나이 : " + student.age); System.out.println("키 : " + student.height); } } public class Student { String name; int age; double height; public Student() { name = "도토리"; age = 33;.. 더보기
[JAVA] 도형 클래스를 객체를 생성하여 도형의 넓이를 구하는 프로그램 만들기 import java.util.Scanner; class Triangle{ double width=0; double height=0; double triangle_area() { return (width*height)/2; } } class Square{ int width=0; int height=0; int square_area() { return(width*height); } } class Circle{ double radius = 0; double circle_area() { return(radius*radius*3.14); } } public class Shape { public static void main(String[] args) { Scanner sc = new Scanner(System... 더보기
[JAVA] 클래스의 객체를 생성하여 멤버 변수에 값을 대입한 다음 출력하기 Q. student클래스의 객체를 생성하여 멤버 변수에 값을 대입한 다음 출력하기 class Student{ public String name; public int age; public double height; } import java.util.Scanner; public class StudentTest { public static void main(String[] args) { Scanner sc = new Scanner(System.in); Student student = new Student(); System.out.println("이름을 입력하세요 ."); student.name = sc.nextLine(); System.out.println("나이를 입력하세요 ."); student.age =.. 더보기
[JAVA] 다형성을 이용하여 동물 울음소리 출력하기(상속, 오버라이딩) Q. Animal 클래스는 동물의 울음소리를 출력해주는 sound함수를 가지고 있다. 그리고 이 Animal 클래스를 상속받는 Dog(개)클래스, Cat(고양이)클래스, Frog(개구리)클래스를 정의하고 Animal 클래스의 sound함수를 각 클래스에 맞게 재 정의하세요. (함수 오버 라이딩의 특성) 1. 메인문 class Polymorphism_1 public class Polymorphism_1 { public static void main(String[] args) { Animal animal = new Animal(); animal= new Cat(); animal.sound(); animal = new Dog(); animal.sound(); animal = new Frog(); animal... 더보기
[JAVA] 2차원 배열을 이용하여 입력한 높이 만큼의 파스칼 삼각형을 저장하려 출력하는 프로그램을 만들기 Q. 2차원 배열(최대 100행 100열)을 이용하여 입력한 높이 만큼의 파스칼 삼각형을 저장하여 출력하는 프로그램을 만들어 보세요. import java.util.Scanner; public class AAAa { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int num; for(;;) { num = sc.nextInt(); if(num 더보기
[JAVA] 배열을 이용하여 피보나치 수열을 저장하여 출력하는 프로그램 만들어보기 import java.util.Scanner; public class Age { public static void main(String [] args) { System.out.print("몇개의 피보나치 수열을 출력하겠습니까? >>"); Scanner sc = new Scanner(System.in); int num = sc.nextInt(); int arr[] = new int[num]; arr[0] = 1; arr[1] = 1; System.out.print(arr[0] + " " + arr[1]+ " "); for(int i=2 ; i 더보기

반응형