티스토리 툴바


JAVA 열공!2011/05/16 12:18
class MethodEx
{
int var1,var2; // Member Varialbes

public int sum(int a ,int b){
return a + b;
}

public static void main(String[] args){
MethodEx me = new MethodEx();
int res = me.sum(1000,-10);
System.out.println("res="+res);
}

}

------------------------------------------------------

class MethodEx2
{
int var;

public void setInt(int var){
this.var=var;
}
public int getInt(){
return var;
}

public static void main(String[] args){
MethodEx2 me2 = new MethodEx2();
me2.setInt(1000);
System.out.println("var:"+me2.getInt());
}

}
Posted by 天淚ㆀ
JAVA 열공!2011/05/16 11:08
class MP3p{
String color;
int memory;
public void memoryUp(int n){
memory += n;
}
public void setColor(String c){
color = c;
}


--------------------------------------------------- 

 class MP3pMain
{
public static void main(String[] args) 
{
MP3p m3 = new MP3p(); // 객체생성
m3.memoryUp(1024);
m3.setColor("RED");

System.out.println(m3.color);
System.out.println(m3.memory);
}
}

---------------------------------------------------
Posted by 天淚ㆀ
JAVA 열공!2011/05/14 01:01
class BreakEx1
{
public static void main(String[] args)
{
for (int i=0;i<3;i++)
{
for (int j=0;j<5;j++)
{
if(j==3) break;
System.out.println("i값:"+i+", j값"+j);
}
}
}
}

------------------------------------------------

class BreakEx2
{
public static void main(String[] args)
{
exit_For: // 레이블설정
for (int i=0; i<3 ; i++ )
{
for (int j=0; j<5 ; j++ )
{
if(j==3) break exit_For;
System.out.println("i값:"+i+", j값:"+j);
}
}
}
}

------------------------------------------------

class CountinueEx1 
{
public static void main(String[] args) 
{
for (int i=0;i<10 ;i++)
{
if(i%4 ==0)//4의배수
continue;
System.out.println("i값:"+i);
}
}
}

------------------------------------------------


class CountinueEx2
{
public static void main(String[] args)
{
label:
for(int i=0;i<5;i++)
{
for(int j=0;j<5;j++)
{
if(j==3) continue label;
System.out.println("i값:"+i+", j값:"+j);
}
}
}
}

Posted by 天淚ㆀ
JAVA 열공!2011/05/14 00:57
class ForEx1
{
public static void main(String[] args)
{
int j = Integer.parseInt(args[0]);
for(int i=1 ; i<=j ; i++)
{
System.out.println(i+"번째 수행");
}
}
}

--------------------------------------------------------

class MultiForEx1
{
public static void main(String[] args)
{
for(int i=1;i<=9;i++)
{
for (int j=2;j<=9;j++)
{
System.out.print(j+"*"+i+"="+ i*j + "\t");
}
System.out.println();
}
}
}

--------------------------------------------------------

class WhileEx1
{
public static void main(String[] args)
{
int sum, su;
sum = su = 0;
int j = Integer.parseInt(args[0]);

while(su<=j)
{
sum += su;
su++;
}
System.out.println("1~"+j+"까지의 합 : "+sum);
}
}

--------------------------------------------------------

class Do_WhileEx1
{
public static void main(String[] args)
{
int su = 5;
String str = "Java DoublePlus";

do
{
System.out.println(str);
}
while (su-- >10);
}
}
Posted by 天淚ㆀ
JAVA 열공!2011/05/14 00:48
class IfEx1
{
public static void main(String[] args)
{
int su1 = Integer.parseInt(args[0]);
String str = "50미만";

if(su1 >= 50)
str = "50이상";
System.out.println(str+"입니다.");
}
}

--------------------------------------------------------

class IfEx2
{
public static void main(String[] args)
{
int su1 = Integer.parseInt(args[0]);
String str;

if (su1 >=50)
str = "50이상";
else
str = "50미만";
System.out.println(str+"입니다");
}
}

--------------------------------------------------------

class IfEx3
{
public static void main(String[] args)
{
int su = Integer.parseInt(args[0]);
String res;

if(su >=40)
res = "고급";
else if(su>=11)
res = "중급";
else if(su>=0)
res = "초급";
else
res = "음수";

System.out.println(res+"입니다");
}
}
 
--------------------------------------------------------

class IfEx4
{
public static void main(String[] args)
{
String data = args[0];
String res;

if(data.equals("포도"))
res = "달다.";
else if(data.equals("수박"))
res = "시원하다.";
else if(data.equals("딸기"))
res = "맛있다.";
else
res = "기타";
System.out.println(res);
}
}
 
--------------------------------------------------------

class SwitchEx1
{
public static void main(String[] args)
{
int month = Integer.parseInt(args[0]);
String res;
switch(month)
{
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:
res = "31"; break;
case 4:
case 6:
case 9:
case 11:
res = "30"; break;
case 2:
res = "28"; break;
default : res = "몰라";
}
System.out.println(month+"월은 "+res+"일까지 입니다.");
}
Posted by 天淚ㆀ