[Java] 문법

JAVA/함수 2014. 10. 28. 17:44
728x90
반응형

JAVA  ---------

 

# Array copy

 

 

- Arrays.copyof(원본, 원본.length);

 

 

- System.arraycopy(원본,인덱스,복사본,인덱스,개수);

 

 

 

 

# Array sort

 

 

- Arrays.sort(배열);

 

 

 

 

# Array 출력

 

 

-System.out.println(Arrays.toString(배열));

 

 

-System.out.println(배열[index]);

 

 

 

 

# foreach 구문 ( 1차원 / 2차원)

 

 

- for(int row : 배열){System.out.println(변수);

 

 

- for(int [ ] col : row){

 

 

      for(int 열 : 행) { System.out.print(col+" "); } }

 

 

 

# input(콘솔)

 

 

- Scanner in = new Scanner(System.in);

 

 

- int num = in.nextInt();  <- 인트형으로 저장

 

 

- String str = in.next();  < 스트링형으로 저장

 

 

 

 

# input (다이얼)

 

 

- String input = JOptionPane.showInputDialog("msg");

 

 

- int number = Integer.parseInt(input) int형으로 변환

 

 

- double number = Double.parseDouble(input); double

 

 

 

 

 

# output(다이얼)

 

 

 - JOptionPane.showMessageDialog(null,"msg");

 

 

 

 

# equals(char비교)

 

 

 - 객체.equals('비교 char')

 

 

 

 

# Character 클래스 (생성자 생성후 사용)

 

 

 - Character.isDigit(num) <- num이 숫자인지 판별

 

 

 - Character isLetter(char) <- char가 알파벳인지 판별(대소상관무)

 

 

 - Character isLowerCase(char) <- char가 소문자인지 판별

 

 

 - Character isUpperCase(char) <- char가 대문자인지 판별

 

 

 

 

# compareTo (글자 길이 비교)

 

 

 - b.compareTo('c')  bc 차이?

 

 

 

 

# StringBuffer 문자열을 더하고 지우고 리버스 가능

 

 

 - StringBuffer buffer = new StringBuffer();  생성자 생성후 사용

 

 

 - buffer.append("str");  <- 문자열 저장 < 추가 저장 가능>

 

 

 - buffer.deleteCharAt(0);  <- 0번째 한글자 삭제

 

 

 - buffer.reverse();  <- 문자열 거꾸로

 

 

 

 

# File 클래스 (생성자 생성후 사용)

 

 

 - String str = System.getProperty("msg");  // 현재 작업 디렉토리 추출

 

 

  - File file = new File(file경로);

 

 

 - file.exists();         // 존재하는가

 

 

 - file.canRead();      // 읽기가 가능한가  

 

 

 -  file.canWrite();    // 쓰기가 가능한가

 

 

 - file.isDirectory()    // 파일이 디렉토리인가

 

 

 - file.isFile();          // 일반 파일인가

 

 

 - file.isHidden();     // 파일이 숨겨져 있는가

 

 

 

 

# File writer

 

 

 - try {

 

     PrintWriter pw = new PrintWriter("입력할 경로");

 

 

    pw.println("str ");

 

 

     pw.close();

 

   } catch (FileNotFoundException e) {

 

 

                          e.printStackTrace();}

 

 

 

 

 # File read

 

 

 -  try{

 

 

  Scanner in = new Scanner("읽어올 경로");

 

 

  int sum = 0;

 

 

  while(in.hasNext()){

 

 

             sum += in.nextInt();  }

 

       JOptionPane.showMessageDialog(null, sum);

 

             in.close();

 

  }catch(FileNotFoundException e) {

 

             e.printStackTrace();}

 

 

 

# split 문자열 자르기

 

 

String input = JOptionPane.showInputDialog("msg");

 

 

String[] num = input.split(" ");

 

 

             num1 = Integer.parseInt(num[0]);

 

 

             num2 = Integer.parseInt(num[1]);            }

 

 

 

 

 

 

# 현재 시간 구하기

 

 

- long currentMillSec = System.currentTimeMillis();

 

  System.out.println("총시간(ms)="+currentMillSec);

 

 

- int currentSec=(int)(currentMillSec/1000);

 

  System.out.println("총시간(sec)="+currentSec);

 

 

            

 

//초에서 시간 구하기

 

 

- int currentHour = (currentSec/3600)%24;

 

  System.out.println("현재시간 = "+currentHour);

 

 

//초에서 분 구하기

 

 

- int currentMin = (currentSec /60)%60;

 

  System.out.println("현재분 = "+currentMin);

 

 

//초에서 초 구하기

 

 

- int currentS = currentSec%60;

 

  System.out.println("현재초 ="+currentS);

 

 

 

 

# 객체의 배열

 

 

- 클래스명[] 객체 = new 클래스명[n];

 

 

    for(int i=0; i < 100; i++) {

 

             객체[i] = new 클래스명(i+1); }

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

728x90
반응형
블로그 이미지

nineDeveloper

안녕하세요 현직 개발자 입니다 ~ 빠르게 변화하는 세상에 뒤쳐지지 않도록 우리모두 열심히 공부합시다 ~! 개발공부는 넘나 재미있는 것~!

,