package a.b.c;
public class StringInt{
public static void main(String args[]){
int x = 1; //지역변수
int y = 2;
System.out.println(" x + y = " + x + y);
System.out.println(" x + y = " + (x + y));
// toString parseXX
// valuOf
// 숫자(문자) --> 문자열
String sVal = 1 + ""; // 사용x
String sVal1 = String.valueOf(1); // 정수1의 값을 String데이터타입 값으로 변환
String sVal2 = 1.0 + ""; // 사용x
String sVal3 = String.valueOf(1.1);// 실수1.1의 값을 String데이터타입 값으로 변환
String sVal4 = 'c'+ ""; // 사용x
String sVal5 = String.valueOf('c');// 문자'c'의 값을 String데이터타입 값으로 변환
String sVal6 = Integer.toString(1);
//Integer래퍼클래스의 valueOf함수로 정수1의 값을 String데이터타입 값으로 변환
String sVal7 = Double.toString(1.1);
//Double래퍼클래스의 valueOf함수로 실수1.1의 값을 String데이터타입 값으로 변환
String sVal8 = Character.toString('c');
//Character래퍼클래스의 valueOf함수로 문자'c'의 값을 String데이터타입 값으로 변환
String sVal9 = Boolean.toString(true);
//Boolean래퍼클래스의 valueOf함수로 문자'c'의 값을 String데이터타입 값으로 변환
// 문자열 --> 숫자
byte bVal = Byte.parseByte("1");
byte bVal1 = Byte.valueOf("1");
byte bVal2 = Byte.valueOf("1").byteValue();
short aVal = Short.parseShort("1");
short aVal1 = Short.valueOf("1");
short aVal2 = Short.valueOf("1").byteValue();
int iVal = Integer.parseInt("1");
long lVal =Long.parseLong("1");
double dVal = Double.parseDouble("1.0");
double dVal1 = Double.valueOf("1.0");
double dVal2 = Double.valueOf("1.0").doubleValue();
System.out.println(iVal);
System.out.println(dVal);
// Object --> 숫자
/*
int iVal3 = Integer.parseInt(1);
int iVal4 = Integer.valueOf(1);
int iVal5 = Integer.valueOf(1).intValue();
double dVal = Double.parseDouble(1.0);
double dVal1 = Double.valueOf(1.0);
double dVal2 = Double.valueOf(1.0).doubleValue();
*/
Integer it = new Integer(1);
Integer it1 = new Integer("1");
System.out.println(" it >>> : " + it);
System.out.println(" it1 >>> : " + it1);
// parseInt(java.lang.String, int)
Integer.parseInt("0", 10); //returns 0
Integer.parseInt("473", 10); //returns 473
Integer.parseInt("+42", 10); //returns 42
Integer.parseInt("-0", 10); //returns 0
Integer.parseInt("-FF", 16); //returns -255
Integer.parseInt("1100110", 2); //returns 102
Integer.parseInt("2147483647", 10); //returns 2147483647
Integer.parseInt("-2147483648", 10); //returns -2147483648
System.out.println(Integer.parseInt("0", 10));
System.out.println(Integer.parseInt("473", 10));
System.out.println(Integer.parseInt("+42", 10));
System.out.println(Integer.parseInt("-0", 10));
System.out.println(Integer.parseInt("-FF", 16));
System.out.println(Integer.parseInt("1100110", 2));
System.out.println(Integer.parseInt("2147483647", 10));
System.out.println(Integer.parseInt("-2147483647", 10));
} // end of main
} // end of StringInt
package a.b.c;
public class StringAscii{
public static void main(String args[]){
String s = "admin";
char cVal0 = s.charAt(0);
char cVal1 = s.charAt(1);
char cVal2 = s.charAt(2);
char cVal3 = s.charAt(3);
char cVal4 = s.charAt(4);
System.out.println("" + cVal0
+ " : " + cVal1
+ " : " + cVal2
+ " : " + cVal3
+ " : " + cVal4);
int iVal0 = cVal0;
int iVal1 = cVal1;
int iVal2 = cVal2;
int iVal3 = cVal3;
int iVal4 = cVal4;
System.out.println("" + (int)cVal0
+ " : " + (int)cVal1
+ " : " + (int)cVal2
+ " : " + (int)cVal3
+ " : " + (int)cVal4);
System.out.println("" + iVal0
+ " : " + iVal1
+ " : " + iVal2
+ " : " + iVal3
+ " : " + iVal4);
}
} // end of StringAscii
package a.b.c;
public class StringAscii_1{
public static void main(String args[]){
// 알파벳 소문자, 대문자를 초기화 해서
// 알파벳 문자 및 아스키코드 10진수, 16진수 콘솔에 출력
String s = "abcdefghijklmnopqrstuvwxyz";
char cVal0 = s.charAt(0);
char cVal1 = s.charAt(1);
char cVal2 = s.charAt(2);
char cVal3 = s.charAt(3);
char cVal4 = s.charAt(4);
char cVal5 = s.charAt(5);
char cVal6 = s.charAt(6);
char cVal7 = s.charAt(7);
char cVal8 = s.charAt(8);
char cVal9 = s.charAt(9);
char cVal10 = s.charAt(10);
char cVal11 = s.charAt(11);
char cVal12 = s.charAt(12);
char cVal13 = s.charAt(13);
char cVal14 = s.charAt(14);
char cVal15 = s.charAt(15);
char cVal16 = s.charAt(16);
char cVal17 = s.charAt(17);
char cVal18 = s.charAt(18);
char cVal19 = s.charAt(19);
char cVal20 = s.charAt(20);
char cVal21 = s.charAt(21);
char cVal22 = s.charAt(22);
char cVal23 = s.charAt(23);
char cVal24 = s.charAt(24);
char cVal25 = s.charAt(25);
int iVal0 = cVal0;
int iVal1 = cVal1;
int iVal2 = cVal2;
int iVal3 = cVal3;
int iVal4 = cVal4;
int iVal5 = cVal5;
int iVal6 = cVal6;
int iVal7 = cVal7;
int iVal8 = cVal8;
int iVal9 = cVal9;
int iVal10 = cVal10;
int iVal11 = cVal11;
int iVal12 = cVal12;
int iVal13 = cVal13;
int iVal14 = cVal14;
int iVal15 = cVal15;
int iVal16 = cVal16;
int iVal17 = cVal17;
int iVal18 = cVal18;
int iVal19 = cVal19;
int iVal20 = cVal20;
int iVal21 = cVal21;
int iVal22 = cVal22;
int iVal23 = cVal23;
int iVal24 = cVal24;
int iVal25 = cVal25;
System.out.println(iVal0);
System.out.println(iVal1);
System.out.println(iVal2);
System.out.println(iVal3);
System.out.println(iVal4);
System.out.println(iVal5);
System.out.println(iVal6);
System.out.println(iVal7);
System.out.println(iVal8);
System.out.println(iVal9);
System.out.println(iVal10);
System.out.println(iVal11);
System.out.println(iVal12);
System.out.println(iVal13);
System.out.println(iVal14);
System.out.println(iVal15);
System.out.println(iVal16);
System.out.println(iVal17);
System.out.println(iVal18);
System.out.println(iVal19);
System.out.println(iVal20);
System.out.println(iVal21);
System.out.println(iVal22);
System.out.println(iVal23);
System.out.println(iVal24);
System.out.println(iVal25);
System.out.println(" 0x" + Integer.toHexString(iVal0));
System.out.println(" 0x" + Integer.toHexString(iVal1));
System.out.println(" 0x" + Integer.toHexString(iVal2));
System.out.println(" 0x" + Integer.toHexString(iVal3));
System.out.println(" 0x" + Integer.toHexString(iVal4));
System.out.println(" 0x" + Integer.toHexString(iVal5));
System.out.println(" 0x" + Integer.toHexString(iVal6));
System.out.println(" 0x" + Integer.toHexString(iVal7));
System.out.println(" 0x" + Integer.toHexString(iVal8));
System.out.println(" 0x" + Integer.toHexString(iVal9));
System.out.println(" 0x" + Integer.toHexString(iVal10));
System.out.println(" 0x" + Integer.toHexString(iVal11));
System.out.println(" 0x" + Integer.toHexString(iVal12));
System.out.println(" 0x" + Integer.toHexString(iVal13));
System.out.println(" 0x" + Integer.toHexString(iVal14));
System.out.println(" 0x" + Integer.toHexString(iVal16));
System.out.println(" 0x" + Integer.toHexString(iVal17));
System.out.println(" 0x" + Integer.toHexString(iVal18));
System.out.println(" 0x" + Integer.toHexString(iVal19));
System.out.println(" 0x" + Integer.toHexString(iVal20));
System.out.println(" 0x" + Integer.toHexString(iVal21));
System.out.println(" 0x" + Integer.toHexString(iVal22));
System.out.println(" 0x" + Integer.toHexString(iVal23));
System.out.println(" 0x" + Integer.toHexString(iVal24));
System.out.println(" 0x" + Integer.toHexString(iVal25));
String st = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
char dVal0 = st.charAt(0);
char dVal1 = st.charAt(1);
char dVal2 = st.charAt(2);
char dVal3 = st.charAt(3);
char dVal4 = st.charAt(4);
char dVal5 = st.charAt(5);
char dVal6 = st.charAt(6);
char dVal7 = st.charAt(7);
char dVal8 = st.charAt(8);
char dVal9 = st.charAt(9);
char dVal10 = st.charAt(10);
char dVal11 = st.charAt(11);
char dVal12 = st.charAt(12);
char dVal13 = st.charAt(13);
char dVal14 = st.charAt(14);
char dVal15 = st.charAt(15);
char dVal16 = st.charAt(16);
char dVal17 = st.charAt(17);
char dVal18 = st.charAt(18);
char dVal19 = st.charAt(19);
char dVal20 = st.charAt(20);
char dVal21 = st.charAt(21);
char dVal22 = st.charAt(22);
char dVal23 = st.charAt(23);
char dVal24 = st.charAt(24);
char dVal25 = st.charAt(25);
int pVal0 = dVal0;
int pVal1 = dVal1;
int pVal2 = dVal2;
int pVal3 = dVal3;
int pVal4 = dVal4;
int pVal5 = dVal5;
int pVal6 = dVal6;
int pVal7 = dVal7;
int pVal8 = dVal8;
int pVal9 = dVal9;
int pVal10 = dVal10;
int pVal11 = dVal11;
int pVal12 = dVal12;
int pVal13 = dVal13;
int pVal14 = dVal14;
int pVal15 = dVal15;
int pVal16 = dVal16;
int pVal17 = dVal17;
int pVal18 = dVal18;
int pVal19 = dVal19;
int pVal20 = dVal20;
int pVal21 = dVal21;
int pVal22 = dVal22;
int pVal23 = dVal23;
int pVal24 = dVal24;
int pVal25 = dVal25;
System.out.println(pVal0);
System.out.println(pVal1);
System.out.println(pVal2);
System.out.println(pVal3);
System.out.println(pVal4);
System.out.println(pVal5);
System.out.println(pVal6);
System.out.println(pVal7);
System.out.println(pVal8);
System.out.println(pVal9);
System.out.println(pVal10);
System.out.println(pVal11);
System.out.println(pVal12);
System.out.println(pVal13);
System.out.println(pVal14);
System.out.println(pVal15);
System.out.println(pVal16);
System.out.println(pVal17);
System.out.println(pVal18);
System.out.println(pVal19);
System.out.println(pVal20);
System.out.println(pVal21);
System.out.println(pVal22);
System.out.println(pVal23);
System.out.println(pVal24);
System.out.println(pVal25);
System.out.println(" 0x" + Integer.toHexString(pVal0));
System.out.println(" 0x" + Integer.toHexString(pVal1));
System.out.println(" 0x" + Integer.toHexString(pVal2));
System.out.println(" 0x" + Integer.toHexString(pVal3));
System.out.println(" 0x" + Integer.toHexString(pVal4));
System.out.println(" 0x" + Integer.toHexString(pVal5));
System.out.println(" 0x" + Integer.toHexString(pVal6));
System.out.println(" 0x" + Integer.toHexString(pVal7));
System.out.println(" 0x" + Integer.toHexString(pVal8));
System.out.println(" 0x" + Integer.toHexString(pVal9));
System.out.println(" 0x" + Integer.toHexString(pVal10));
System.out.println(" 0x" + Integer.toHexString(pVal11));
System.out.println(" 0x" + Integer.toHexString(pVal12));
System.out.println(" 0x" + Integer.toHexString(pVal13));
System.out.println(" 0x" + Integer.toHexString(pVal14));
System.out.println(" 0x" + Integer.toHexString(pVal15));
System.out.println(" 0x" + Integer.toHexString(pVal16));
System.out.println(" 0x" + Integer.toHexString(pVal17));
System.out.println(" 0x" + Integer.toHexString(pVal18));
System.out.println(" 0x" + Integer.toHexString(pVal19));
System.out.println(" 0x" + Integer.toHexString(pVal20));
System.out.println(" 0x" + Integer.toHexString(pVal21));
System.out.println(" 0x" + Integer.toHexString(pVal22));
System.out.println(" 0x" + Integer.toHexString(pVal23));
System.out.println(" 0x" + Integer.toHexString(pVal24));
System.out.println(" 0x" + Integer.toHexString(pVal25));
} // end of main
} // end of StringAscii_1
package a.b.c;
public class StringAscii_2{
public static void main(String args[]){
// 알파벳 소문자 대문자를 초기화해서 알파벳 문자와 아스키코드 10진수 16진수로 콘솔에 출력
String apb = "abCDefGHIjklmnOpQRstuvwXyz";
String apbL = apb.toLowerCase();
String apbU = apb.toUpperCase();
System.out.println(" apbL >>> : " + apbL);
System.out.println(" apbU >>> : " + apbU);
for (int i=0; i < apb.length(); i++ )
{
System.out.println("" + apbL.charAt(i);+
" : " + (int)apbL.charAt(i)
+ " : 0x" + Integer.toHexString((int)abpL.charAt(i))
+ " : " + apbU.charAt(i)
+ " : " + (int)apbU.charAt(i)
+ " : 0x" + Integer.toHexString((int)apbU.charAt(i)));
}
} // end of main
} // end of StringAscii_2
'수업' 카테고리의 다른 글
10월 16일 - 문자아스키, 객체생성후초기값, printf, (0) | 2018.10.16 |
---|---|
10월 15일 - 기본자료형초기값, 형변환 (0) | 2018.10.15 |
10월 11일 - 명령행인수(CommandLineArg) (0) | 2018.10.11 |
10월 10일 - 생성자, 패키지컴파일, import (0) | 2018.10.10 |
10월 8일 - static, class, Literal, MethodMath (0) | 2018.10.08 |
댓글