----- 시작단과 끝단을 입력받아서 구구단 수행 -----
import java.io.*;
public class Gugu
{
public static void main(String[] args) throws IOException // 입력이 있으면
{ // 해당 메소드에
int start, end; // 꼭 써준다.
System.out.print("start no :");
start = System.in.read()-48; // 숫자1자를 입력 받는다.
System.in.read(); // 엔터키 처리
System.out.println();
System.out.print("end no :");
end = System.in.read()-48;
System.out.println();
for(int i=start; i<=end; i++) // 구구단 처리
{
System.out.println();
System.out.println(i+" <dan>");
for(int j=1; j<10; j++)
{
System.out.println(i+" * "+j+" = "+(i*j));
}
}
}
}
-------------------------------------------------------------------------
--------------- 나이 구하기 ------------------
import java.io.*; // 입출력
import java.util.*; // Calendar
public class Jumin
{
public static void main(String[] args)throws IOException
{
// 문자열을 입력받기 위하여 임시 저장소인 버퍼를 생성한다.
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.print("input your jumin no:");
String id = br.readLine(); // 엔터키가 입력될때까지 읽어온다.
int birth = Integer.parseInt(id.substring(0,2));
Calendar cal = Calendar.getInstance(); // 현재년도를 구한다.
int year = cal.get(Calendar.YEAR);
if((id.charAt(7)-48)<3)
{
System.out.println("age :"+(year-(1900+birth)+1));
}
else
{
System.out.println("age :"+(year-(2000+birth)+1));
}
}
}
---------------------------------------------------------------------------
----------- Package 생성 및 활용 ---------------
import kr.co.choongang.Greetings; // 경로지정
public class PackageMakeTest
{
public static void main(String[] args)
{
Greetings g = new Greetings(); // 객체 생성 및 함수호출
g.hellow("jin");
}
}
---------------------------------------------
package kr.co.choongang; // Package 생성
public class Greetings // 호출될 함수들
{
public Greetings(){}
public void hi(String name)
{
System.out.println("Hi, "+name);
}
public void goodMorning(String name)
{
System.out.println("Good morning"+name);
}
public void hellow(String name)
{
System.out.println("Hellow"+name);
}
public void yahoo()
{
System.out.println("Yahoo~~");
}
}
---------------------------------------------------------------------------
'JAVA/JSP > Java' 카테고리의 다른 글
Exception/ Sort (0) | 2008.07.14 |
---|---|
instanceof/StringTokenizer/innerclass (0) | 2008.07.14 |
Choice/Checkbox/List/TextArea //Event (0) | 2008.07.14 |
ActionListener/ WindowListener/ Dialog (1) | 2008.07.14 |
Choice/ List / TextField / TextArea ,Layout, Menu (0) | 2008.07.14 |