forked from giakinh0823/java-programming-tutorial
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPart3.java
More file actions
65 lines (56 loc) · 1.63 KB
/
Copy pathPart3.java
File metadata and controls
65 lines (56 loc) · 1.63 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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package Workshop1;
import java.util.ArrayList;
import java.util.Scanner;
import java.util.StringTokenizer;
/**
*
* @author giaki
*/
class Student{
private String name;
public Student() {
}
public Student(String name) {
this.name = name;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
@Override
public String toString() {
return name;
}
}
public class Part3 {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
ArrayList<Student> listStudents = new ArrayList<Student>();
System.out.print("Enter number student: ");
int n=scanner.nextInt();
scanner.nextLine();
for(int i=0 ; i<n;i++){
System.out.print("Enter name student " + (i+1) + ": ");
String name=scanner.nextLine();
name=name.trim().replaceAll("\\s+", " ");
StringTokenizer token = new StringTokenizer(name, " ");
name="";
while(token.hasMoreTokens()){
String newName =token.nextToken();
name+=newName.substring(0,1).toUpperCase() + newName.substring(1) + " ";
}
Student student = new Student(name.trim());
listStudents.add(student);
}
for (Student student : listStudents) {
System.out.println(student.toString());
}
}
}