JAVA _LENGTH
언어/java2017. 12. 26. 10:19
자바에서 배열의 길이를 구하는 함수 .length;
문자열의 길이를 구하는 함수 .length();
int[] t_arry;
t_arry = new int[10];
int arrayLength = t_arry.length;
System.out.printf("length => %d\n", arrayLength);
String greeting = "Hello world";
int strLength = greeting.length();
System.out.printf("str:length => %d\n",strLength);
파이썬에서는 조금 더 편하게 len 로 배열과 문자열의 길이를 측정할 수 있다.
def main():
sValue = "Hello world"
strlen = len(sValue)
print ("strLen => {}".format(strlen))
lValue = [1,2,3,4,5]
listLen = len(lValue)
print ("listLen => {}".format(listLen))
if __name__ == "__main__":
main()
그렇다면 c언어에서는 ...
char strValue[] = "Hello World"; unsigned int sLen = strlen(strValue); printf("sLen => %d \n", sLen); int sNumber[] = { 10, 20, 30, 40, 50 }; unsigned int sArr = (int)(sizeof(sNumber) / sizeof(int)); printf("sArr => %d \n", sArr);
c++
std::string sVal = "Kim Jun Hyeon"; int(vlen) = sVal.length(); std::cout << "vlen => " << vlen << std::endl; int sArr[5] = { 0, }; int Len = sizeof(sArr) / sizeof(int); std::cout << "Len => " << Len << std::endl;
'언어 > java' 카테고리의 다른 글
list => sort (0) | 2017.12.26 |
---|---|
배열에서 최댓값과 최솟값 (0) | 2017.12.26 |
random_shuffle (python 과 비교) (0) | 2017.12.25 |
자바 성적 입력 (0) | 2017.12.25 |
java 예외처리 - (0) | 2017.12.25 |