Fix the following code so it produces the following output:
one word |
Note: You should achieve this WITHOUT changing any print statements.
Solution
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
class Main
{
public static void main(String[] args)
{
String output ="";
String text = "hello";
if (text.indexOf(" ") == -1) //if a space doesn't exist
{
output = "one word";
}
else
{
output = "more than one word";
}
System.out.println(output);
}
}
|
반응형
'Java_beginner(Repl.it) > Auto-Graded-Course(AP CS A)' 카테고리의 다른 글
059 - Scope and Global Variables 2 (0) | 2020.02.03 |
---|---|
057 - Accumulator Method String Challenge 1 (optional) (0) | 2019.12.26 |
056 - Accumulator Method String Practice 4 (0) | 2019.12.26 |
055 - Accumulator Method String Practice 3 (0) | 2019.12.26 |
054 - Accumulator Method String Practice 2 (0) | 2019.12.26 |