-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathString7.java
More file actions
37 lines (27 loc) · 1.02 KB
/
String7.java
File metadata and controls
37 lines (27 loc) · 1.02 KB
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
import java.util.*;
public class String7 {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int n = Integer.parseInt(scanner.nextLine());
System.out.println("Flight Details:");
for (int i = 1; i <= n; i++) {
String flightCode = scanner.nextLine();
String[] parts = flightCode.split("-");
String firstPart = parts[0];
String origin = parts[1];
String destination = parts[2];
String airline = "";
String flightNumber = "";
for (char ch : firstPart.toCharArray()) {
if (Character.isLetter(ch)) {
airline += ch;
} else if (Character.isDigit(ch)) {
flightNumber += ch;
}
}
System.out.println(i + ". Airline: " + airline + ", Flight: " + flightNumber +
", From: " + origin + ", To: " + destination);
}
scanner.close();
}
}