-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQuestion76_Email1.java
More file actions
42 lines (25 loc) · 938 Bytes
/
Question76_Email1.java
File metadata and controls
42 lines (25 loc) · 938 Bytes
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
31
32
33
34
35
36
37
38
39
40
41
42
package week6_String;
import java.util.Scanner;
public class Question76_Email1 {
public static void main(String[] args) {
// olcay // Jul 6, 2020
/* In this task, you need to swap first name with last name in the email. If email doesn't contains underscore - do not anything.
Example:
input: mike_tyson@gmail.com
output: tyson_mike@gmail.com
Example:
input: barakobama@gmail.com
output: barakobama@gmail.com
*/
Scanner scan = new Scanner(System.in);
System.out.println("email:");
String email = scan.next();
if(email.contains("_")) {
String name = email.substring(0, email.indexOf('_'));
String surname = email.substring(email.indexOf('_')+1, email.indexOf('@'));
System.out.println(surname + "_" + name + "@gmail.com");
}else {
System.out.println(email);
}
}
}