"Java 문자열"의 두 판 사이의 차이

 
(사용자 2명의 중간 판 10개는 보이지 않습니다)
1번째 줄: 1번째 줄:
==개요==
==개요==
;Java 문자열을 다뤄본다.
;Java 문자열을 다뤄본다.
<syntaxhighlight lang="java" run>
public class helloWorld {
    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);


<syntaxhighlight lang='java' run>
public class MyClass {
    public static void main(String args[]) {


        String first_string = "Hello World";
       
        //문자열의 길이 확인하기
        String first_string2= "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
        System.out.println("The length of the first_string2 string is: " + first_string2.length());
       
        //대문자 전환, 소문자전환
        String first_string3 = "Hello World";
        System.out.println(first_string3.toUpperCase());  // Outputs "HELLO WORLD"
        System.out.println(first_string3.toLowerCase());  // Outputs "hello world"
       
        //문자열내에서 문자열 찾기
        String first_string4 = "Please locate where 'locate' occurs!";
        System.out.println(first_string4.indexOf("locate")); // Outputs 7
       
        String first = "John";
        String last = "Doe";
        //문자열 붙이는 방법 1
        System.out.println(first + last );
       
        //문자열 붙이는 방법 2
        System.out.println(first.concat(last));
     }
     }
}
}
</syntaxhighlight>


</syntaxhighlight>
[[분류:Java 문자열]]

2021년 8월 22일 (일) 18:46 기준 최신판

개요[ | ]

Java 문자열을 다뤄본다.
Java
CPU
1.3s
MEM
72M
0.8s
Copy
public class MyClass {
    public static void main(String args[]) {

        String first_string = "Hello World";
        
        //문자열의 길이 확인하기
        String first_string2= "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
        System.out.println("The length of the first_string2 string is: " + first_string2.length());
        
        //대문자 전환, 소문자전환
        String first_string3 = "Hello World";
        System.out.println(first_string3.toUpperCase());   // Outputs "HELLO WORLD"
        System.out.println(first_string3.toLowerCase());   // Outputs "hello world"
        
        //문자열내에서 문자열 찾기
        String first_string4 = "Please locate where 'locate' occurs!";
        System.out.println(first_string4.indexOf("locate")); // Outputs 7
        
        String first = "John";
        String last = "Doe";
        //문자열 붙이는 방법 1
        System.out.println(first + last );
        
        //문자열 붙이는 방법 2
        System.out.println(first.concat(last));
    }
}
The length of the first_string2 string is: 26
HELLO WORLD
hello world
7
JohnDoe
JohnDoe