The variable "name" holds a String user input
Write a conditional statement starting on line 9 that does the following:
-
If name is equal to "Chen", print "teacher"
-
For any other input, print "student"
Examples:
In: Chen teacher In: Faa student |
1
2
3
4
5
6
7
8
9
10
11
12
13
|
class Main {
public static void main(String[] args) {
Scanner inp = new Scanner(System.in);
System.out.print("In:");
//DO NOT CHANGE ABOVE CODE! Write your code below
String temp= name.equals("Chen")?"teacher":"student";
System.out.println(temp);
}
}
|
Stirng temp=name.equals("Chen")?"teacher":"student";
System.out.println(temp);
==
if(name=="Chen"){
System.out.println("teacher");
else{
System.out.println("student");
}
반응형
'Java_beginner(Repl.it) > Auto-Graded-Course(AP CS A)' 카테고리의 다른 글
019 - For Loops 1 (0) | 2019.11.30 |
---|---|
018 - Conditional Statement Practice 4 (0) | 2019.11.28 |
016 - Conditional Statement Practice 2 (0) | 2019.11.28 |
015 - Conditional Statement Practice 1 (0) | 2019.11.26 |
011 - String Methods Practice 2 (0) | 2019.11.26 |