forked from SLIIT-FacultyOfComputing/sliit-faculty-of-computing-se2012-ooad-practical-02-SE2012-OOAD-Practical_002
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Part01.java
58 lines (46 loc) · 2.05 KB
/
Part01.java
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
import java.util.Scanner;
public class Part01{
public static void main(String[] arg){
Scanner kybrd = new Scanner(System.in);
String[] fulname,parts;
fulname = new String[2];
parts = new String[3];
int i=0;
while(i<2){ //loop for to enter two names
StringBuilder name = new StringBuilder();
System.out.printf("\n\nEnter your First Name: ");
name.append(kybrd.nextLine()); // getting first name
System.out.printf("\nEnter your Middle Name: ");
name.append(" " + kybrd.nextLine()); // getting middle name
System.out.printf("\nEnter your Last Name: ");
name.append(" " + kybrd.nextLine()); // getting last name
fulname[i] = name.toString(); // fullname teransfer to "fulname" array
int count = 0;
parts = fulname[i].split(" "); // spliting the full name to 3 parts and store in "parts" array
fulname[i] = fulname[i].toUpperCase(); // converting all letters to uppercase
for(char c : fulname[i].toCharArray()){ // for count vowels
if(c == 'A' || c == 'E' || c == 'I' || c == 'O' || c == 'U'){
count = count +1;
}
}
fulname[i] = fulname[i].replace("A","@"); // replace A-> @
fulname[i] = fulname[i].replace("E","3"); // replace E-> 3
System.out.println("\n\nName = " + fulname[i]);
System.out.println("\nFirst Name = " + parts[0]);
System.out.println("Middle Name = " + parts[1]);
System.out.println("Last Name = " + parts[2]);
System.out.println("Vowels in name : " + count);
i = i +1;
}
if(fulname[0].equals(fulname[1])){ //check the names we entered are equal or not
System.out.println("Names are same!");
}
else{
System.out.println("Names are different");
}
System.out.printf("\nEnter a data to Trim : ");
String Trim = kybrd.nextLine();
Trim = Trim.trim(); //Trim the entered string
System.out.println("Trimed Value : " + Trim);
}
}