문제
풀이
import java.util.Scanner;
public class Solution {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String str = sc.next();
int n = sc.nextInt();
for(int i = 0; i < n; i++) {
System.out.print(str);
}
sc.close();
}
}
class Main {
public static void main(String[] args) {
String s = "When I suddenly look back";
for (int i = 0; i < s.length(); i++) {
System.out.print(s.charAt(i));
}
}
}
class Main {
public static void main(String[] args) {
String s = "When I suddenly look back";
char[] chars = s.toCharArray();
for (char ch: chars) {
System.out.print(ch);
}
}
}
import java.text.CharacterIterator;
import java.text.StringCharacterIterator;
class Main {
public static void main(String[] args) {
String s = "When I suddenly look back";
CharacterIterator it = new StringCharacterIterator(s);
while (it.current() != CharacterIterator.DONE) {
System.out.print(it.current());
it.next();
}
}
}
class Main {
public static void main(String[] args) {
String s = "When I suddenly look back";
String[] arr = s.split("");
for (String ch: arr) {
System.out.print(ch);
}
}
}
출처
https://school.programmers.co.kr/learn/courses/30/lessons/181950
https://www.techiedelight.com/ko/iterate-over-characters-string-java/
'Algorithm > Programmers' 카테고리의 다른 글
[Programmers] Lv.0 / 덧셈식 출력하기 / Java (0) | 2023.10.17 |
---|---|
[Programmers] Lv.0 / 특수문자 출력하기 / Java (0) | 2023.10.17 |
[Programmers] Lv.0 / 대소문자 바꿔서 출력하기 / Java (0) | 2023.10.17 |
[Programmers] Lv.0 / a와 b 출력하기 / Java (0) | 2023.10.17 |
[Programmers] Lv.0 / 문자열 출력하기 / Java (0) | 2023.10.17 |
댓글