Programming/Java2014. 6. 9. 23:53

public static int getRandomNumber(){

Random rand = new Random();

String rst = Integer.toString(rand.nextInt(8) + 1);

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

rst += Integer.toString(rand.nextInt(9));

}

return Integer.parseInt(rst);

}

'Programming > Java' 카테고리의 다른 글

현재 시간 구하기  (0) 2014.06.06
난수(Random Number) 출력  (0) 2014.05.15
(Java) String 반대로 순서 변경  (0) 2014.04.16
(Java) Byte Array to Binary and Binary to Byte Array  (0) 2014.04.14
Posted by WI_K
Programming/Java2014. 6. 6. 18:37

안드로이드 현재시간 구하기 및 포맷지정 방식 예제입니다.

물론 자바에서도 가능하구요.


// 현재 시간을 msec으로 구한다.

long now = System.currentTimeMillis();


// 현재 시간을 저장 한다.

Date date = new Date(now);


// 시간 포맷 지정

SimpleDateFormat CurDateFormat = new SimpleDateFormat("yyyy년 MM월 dd일");

SimpleDateFormat CurTimeFormat = new SimpleDateFormat("HH시 mm분");

SimpleDateFormat CurYearFormat = new SimpleDateFormat("yyyy");

SimpleDateFormat CurMonthFormat = new SimpleDateFormat("MM");

SimpleDateFormat CurDayFormat = new SimpleDateFormat("dd");

SimpleDateFormat CurHourFormat = new SimpleDateFormat("HH");

SimpleDateFormat CurMinuteFormat = new SimpleDateFormat("mm");


// 지정된 포맷으로 String 타입 리턴 

String strCurDate = CurDateFormat.format(date);

String strCurTime = CurTimeFormat.format(date);

String strCurYear = CurYearFormat.format(date);

String strCurMonth = CurMonthFormat.format(date);

String strCurDay = CurDayFormat.format(date);

String strCurHour = CurHourFormat.format(date);

String strCurMinute = CurMinuteFormat.format(date);



'Programming > Java' 카테고리의 다른 글

8자리 난수구하기  (0) 2014.06.09
난수(Random Number) 출력  (0) 2014.05.15
(Java) String 반대로 순서 변경  (0) 2014.04.16
(Java) Byte Array to Binary and Binary to Byte Array  (0) 2014.04.14
Posted by WI_K
Programming/Java2014. 5. 15. 19:46

http://hyeonstorage.tistory.com/160

'Programming > Java' 카테고리의 다른 글

8자리 난수구하기  (0) 2014.06.09
현재 시간 구하기  (0) 2014.06.06
(Java) String 반대로 순서 변경  (0) 2014.04.16
(Java) Byte Array to Binary and Binary to Byte Array  (0) 2014.04.14
Posted by WI_K
Programming/Java2014. 4. 16. 15:06

new StringBuilder(hi).reverse().toString()

'Programming > Java' 카테고리의 다른 글

8자리 난수구하기  (0) 2014.06.09
현재 시간 구하기  (0) 2014.06.06
난수(Random Number) 출력  (0) 2014.05.15
(Java) Byte Array to Binary and Binary to Byte Array  (0) 2014.04.14
Posted by WI_K
Programming/Java2014. 4. 14. 20:31

public static String byteArraytoBinary( byte[] bytes ){

   StringBuilder sb = new StringBuilder(bytes.length * Byte.SIZE);

   for( int i = 0; i < Byte.SIZE * bytes.length; i++ )

       sb.append((bytes[i / Byte.SIZE] << i % Byte.SIZE & 0x80) == 0 ? '0' : '1');

   

   return sb.toString();

}

public static byte[] binaryToByteArray( String s ){

   int sLen = s.length();

   byte[] toReturn = new byte[(sLen + Byte.SIZE - 1) / Byte.SIZE];

   char c;

   for( int i = 0; i < sLen; i++ )

       if( (c = s.charAt(i)) == '1' )

           toReturn[i / Byte.SIZE] = (byte) (toReturn[i / Byte.SIZE] | (0x80 >>> (i % Byte.SIZE)));

       else if ( c != '0' )

           throw new IllegalArgumentException();

   return toReturn;

}

'Programming > Java' 카테고리의 다른 글

8자리 난수구하기  (0) 2014.06.09
현재 시간 구하기  (0) 2014.06.06
난수(Random Number) 출력  (0) 2014.05.15
(Java) String 반대로 순서 변경  (0) 2014.04.16
Posted by WI_K