1번째 줄: | 1번째 줄: | ||
==개요== | ==개요== | ||
;Java 문자열을 다뤄본다. | ;Java 문자열을 다뤄본다. | ||
<syntaxhighlight lang='java' run> | |||
public class Main { | |||
public static void main(String[] args) { | |||
String greeting = "Hello"; | |||
System.out.println(greeting); | |||
} | |||
} | |||
</syntaxhighlight> | |||
<syntaxhighlight lang="java" run> | <syntaxhighlight lang="java" run> | ||
public class Main{ | public class Main{ | ||
10번째 줄: | 22번째 줄: | ||
System.out.println("The length of the txt string is: " + txt.length()); | System.out.println("The length of the txt string is: " + txt.length()); | ||
//대문자 전환, | //대문자 전환, 소문자전환 | ||
String txt = "Hello World"; | String txt = "Hello World"; | ||
System.out.println(txt.toUpperCase()); // Outputs "HELLO WORLD" | System.out.println(txt.toUpperCase()); // Outputs "HELLO WORLD" |
2021년 8월 22일 (일) 18:13 판
개요
- Java 문자열을 다뤄본다.
Java
Copy
public class Main {
public static void main(String[] args) {
String greeting = "Hello";
System.out.println(greeting);
}
}
⚠️
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));
}
}
Loading
편집자 에어컨 Jmnote
로그인하시면 댓글을 쓸 수 있습니다.