For you to do:
Given a string variable "word", do the following tests
If the word ends in "y", print "-ies"
If the word ends in "ey", print "-eys"
If the word ends in "ife", print "-ives"
If none of the above is true, print "-s"
No more than one should be printed.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
class Main {
public static void main(String[] args) {
Scanner inp = new Scanner(System.in);
System.out.print("In:");
String word = inp.nextLine();
//DO NOT CHANGE ABOVE CODE! Write your code below
char sw=word.charAt(word.length()-1);
switch(sw) {
case 'y':
if(word.charAt(word.length()-2)=='e') {
System.out.println("-eys");
break;
}else {
System.out.println("-ies");
break;
}
case 'e':
if(word.charAt(word.length()-2)=='f'&&word.charAt(word.length()-3)=='i') {
System.out.println("-ives");
break;
}
default:
System.out.println("-s");
}
}
}
|
h |
반응형
'Java_beginner(Repl.it) > Auto-Graded-Course(AP CS A)' 카테고리의 다른 글
020 - For Loops 2 (0) | 2019.11.30 |
---|---|
019 - For Loops 1 (0) | 2019.11.30 |
017 - Conditional Statement Practice 3 (0) | 2019.11.28 |
016 - Conditional Statement Practice 2 (0) | 2019.11.28 |
015 - Conditional Statement Practice 1 (0) | 2019.11.26 |