34번째 줄: | 34번째 줄: | ||
} | } | ||
</syntaxhighlight> | </syntaxhighlight> | ||
[[분류:Java 문자열]] |
2021년 8월 22일 (일) 18:39 판
개요
- Java 문자열을 다뤄본다.
Java
Copy
public class Main {
public static void main(String[] args) {
String greetings = "Hello World";
//문자열의 길이 확인하기
String txt = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
System.out.println("The length of the txt string is: " + txt.length());
//대문자 전환, 소문자전환
String txt = "Hello World";
System.out.println(txt.toUpperCase()); // Outputs "HELLO WORLD"
System.out.println(txt.toLowerCase()); // Outputs "hello world"
//문자열내에서 문자열 찾기
String txt = "Please locate where 'locate' occurs!";
System.out.println(txt.indexOf("locate")); // Outputs 7
//문자열 붙이는 방법 1
String firstName = "John";
String lastName = "Doe";
System.out.println(firstName + " " + lastName);
//문자열 붙이는 방법 2
String firstName = "John ";
String lastName = "Doe";
System.out.println(firstName.concat(lastName));
}
}
Running
편집자 에어컨 Jmnote
로그인하시면 댓글을 쓸 수 있습니다.