Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- StringBuilder sb = new StringBuilder();
- String randomWord = "Hello world!";
- for (int i = 0; i < randomWord.length(); i++) {
- System.out.println("Character " + i + " is:" + randomWord.charAt(i));
- }
- char space = ' ';
- int i = 0;
- String newWord = "";
- while (randomWord.charAt(i) != space && i != randomWord.length() - 1) {
- newWord += "" + randomWord.charAt(i);
- sb.append(randomWord.charAt(i)); // "StringBuilder" ползва по-малко памет
- i++;
- }
- System.out.println(newWord);
- System.out.println(sb.toString());
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement