http://www.hackerschool.org/HS_Boards/zboard.php?desc=asc&no=6320 [º¹»ç]
class Student
{
public String name;
public int age;
public Student(String Name, int Age)
{
name = Name;
age = Age;
}
public String getName()
{
return name;
}
public int getAge()
{
return age;
}
public void setName(String Name)
{
name = Name;
}
public void setAge(int Age)
{
age = Age;
}
public String toString()
{
return ("Name of Student : " + name + " , Age of Student : " + age);
}
}
-------------------------------------------------------------------------------------------------------
1¹ø
-------------------------------------------------------------------------------------------------------
import java.util.*;
class Main
{
public static void main ( String[] args )
{
Student s1, s2;
s1 = new Student ("", 0);
s2 = new Student ("", 0);
String name1, name2;
int age1, age2;
Student [] ST = new Student [5];
System.out.println("What is name");
Scanner sc1 = new Scanner(System.in);
name1 = sc1.next();
s1.setName("Name of Student : " + name1 + " , Age of Student : ");
System.out.println("What is age");
Scanner sc2 = new Scanner(System.in);
age1 = sc2.nextInt();
s1.setAge(age1);
System.out.println("What is name");
Scanner sc3 = new Scanner(System.in);
name2 = sc3.next();
s2.setName("Name of Student : " + name2 + " , Age of Student : ");
System.out.println("What is age");
Scanner sc4 = new Scanner(System.in);
age2 = sc4.nextInt();
s2.setAge(age2);
for (int i=0; i<ST.length; i++) {
ST[0] = (s1);
}
for (int i=0; i<ST.length; i++) {
ST[1] = (s2);
}
System.out.println("Student info:");
System.out.println(ST[0].toString());
System.out.println("Student info:");
System.out.print(ST[1].toString());
}
}
-------------------------------------------------------------------------------------------------------
2¹ø
-------------------------------------------------------------------------------------------------------
import java.util.*;
class fourthmain
{
public static void main ( String[] args )
{
Student s1;
s1 = new Student ("", 0);
String name1;
int age1;
Student [] ST = new Student [3];
int H = 0;
String N = ("");
for (int i=0; i<ST.length; i++) {
aw wdST[0] = (s1);
System.out.println("What is name");
Scanner sc = new Scanner(System.in);
name1 = sc.next();
s1.setName(name1);
System.out.println("What is age");
Scanner sc1 = new Scanner(System.in);
age1 = sc1.nextInt();
s1.setAge(age1);
if (H <=age1) {
H = age1;
N = name1;
}
}
System.out.println("Student info:");
System.out.println(ST[0].toString());
System.out.println("Student info:");
System.out.println(ST[1].toString());
System.out.println("Oldest person is : " + N + " ,with the age of " + H);
}
}
-------------------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------------------
ÀÏ´Ü student class¸¦ ¸¸µé°í mainÀ» ¸¸µé¾ú´Âµ¥
student¿¡¼ tostringÀ¸·Î name + age¸¦ ¾Æ¿ôDz ÇÒ ¼ö ÀÖ°ÔÇÏ°í
main¿¡¼ s1 Áï name+age¸¦ °¡Áø °ªÀ» ¸¸µé¾ú´Âµ¥ 1¹ø ÇÁ·Î±×·¥À¸·ÎÇϸé ÀߵǴµ¥
System.out.println("What is name");
Scanner sc1 = new Scanner(System.in);
name1 = sc1.next();
s1.setName("Name of Student : " + name1 + " , Age of Student : ");
System.out.println("What is age");
Scanner sc2 = new Scanner(System.in);
age1 = sc2.nextInt();
s1.setAge(age1);
ºÎºÐÀ» loop¾È¿¡ ³ÖÀ¸¸é ¾Æ¿ôDzÀÌ
What is name
rick
What is age
13
What is name
anto
What is age
15
What is name
jeff
What is age
18
Student info:
Name of Student : Name of Student : jeff , Age of Student : , Age of Student : 18
Student info:
Name of Student : Name of Student : jeff , Age of Student : , Age of Student : 18
Student info:
Name of Student : Name of Student : jeff , Age of Student : , Age of Student : 18
Name is jeffage is 18
ÀÌ·¸°Ô µÇ¿© ±×·¯´Ï±ñ student info¿¡ ³ª¿À´Â studentÀ̸§À̶û ³ªÀÌ°¡ ¸¶Áö¸·¿¡ ³Ö¾ú´ø °ªÀÌ¿¡¿ä
arrary ST[0],ST[1],ST[2]°¡ °¢°¢ ³ª¿Í¾ß Çϴµ¥ ¿Ö ÀÌ·¸°Ô ³ª¿À´Â °ÅÁÒ??
|
Hit : 3381 Date : 2013/03/28 12:11
|