๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
Java

[Java-๊ธฐ์ดˆ] ํด๋ž˜์Šค · ๋ฉ”์„œ๋“œ ๊ธฐ์ดˆ, ์‚ฌ์น™์—ฐ์‚ฐ

by ์ฝ”๋”ฉํ•˜๋Š” ๋ถ•์–ด 2021. 2. 16.
๋ฐ˜์‘ํ˜•

*ํด๋ž˜์Šค๋ž€?

package classpart;

public class classStudent {  // class=ํด๋ž˜์Šค๋ฅผ ๋งŒ๋“œ๋Š” ์˜ˆ์•ฝ์–ด, classStudent=ํด๋ž˜์Šค ์ด๋ฆ„

    // ๋ฉค๋ฒ„ ๋ณ€์ˆ˜
    int studentID;  
    String studentName;
    int grade;
    String address;
}

 

 

 

*Person ํด๋ž˜์Šค ๋งŒ๋“ค๊ธฐ

package classpart;

public class Person {  

    String name;
    int height;
    double weight;
    char gender;
    boolean married;
}

 

 

 

*ํ•™์ƒ ์ด๋ฆ„๊ณผ ์ฃผ์†Œ ์ถœ๋ ฅํ•˜๋Š” ๋ฉ”์„œ๋“œ ๋งŒ๋“ค๊ธฐ

package classpart;

public class Student {

	int studentID;
	String studentName;
	int grade;
	String address;

	public void showStudentInfo() {  // ๋ฉ”์„œ๋“œ ์ถ”๊ฐ€
		System.out.println(studentName + "," + address); // ์ด๋ฆ„, ์ฃผ์†Œ
	}
}

 

 

 

*์‚ฌ์น™ ์—ฐ์‚ฐ ํ•จ์ˆ˜ ๊ตฌํ˜„ํ•˜๊ธฐ

public static int add(int n1, int n2) {
	int result = n1 + n2;
	return result;
}

public static int sub(int n1, int n2) {
	int result = n1 - n2;
	return result;
}

public static int gob(int n1, int n2) {
	int result = n1 * n2;
	return result;
}

public static int div(int n1, int n2) {
	int result = n1 / n2;
	return result;
}

 

 

 

*์‚ฌ์น™์—ฐ์‚ฐ์„ ์‹ค์ˆ˜๊ฐ’์œผ๋กœ ์ถœ๋ ฅ๋˜๊ฒŒ ํ•˜๊ธฐ

public static double div(int n1, int n2) {
	double result = (double) n1 / n2;
	return result;
}
๋ฐ˜์‘ํ˜•

๋Œ“๊ธ€