-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOperation6.java
More file actions
48 lines (45 loc) · 1.77 KB
/
Operation6.java
File metadata and controls
48 lines (45 loc) · 1.77 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
package com.myfirstjava.program;
import java.net.*;
import java.io.*;
//Omer Mohammed Abbas-om17102
//om17102@auis.edu.krd
public class Operation6 { //Server 5
public static void main(String[] args) {
int portNumber = 5252;
try {
ServerSocket serverSocket = new ServerSocket(portNumber);
Socket conn = serverSocket.accept();
InputStream in = conn.getInputStream();
OutputStream out = conn.getOutputStream();
DataInputStream din = new DataInputStream(in);
DataOutputStream dout = new DataOutputStream(out);
do {
String txt = din.readUTF();
System.out.println(txt);
txt = txt.toLowerCase();
char[] chars = txt.toCharArray();
int count = 0;
for (int i = 0; i <txt.length(); i++) {
if (txt.charAt(i) == 'u') {
count++;
}
}
System.out.println("Total no of vowels (u) in string are: " + count);
int counter = 0;
char ch[] = new char [txt.length()];
for (int i =0; i < txt.length(); i++) {
ch[i]= txt.charAt(i);
if( ((i>0)&&(ch[i]!=' ')&&(ch[i-1]==' ')) || ((ch[0]!=' ')&&(i==0)) ) {
counter++;
}
}
System.out.println("number of words: " + counter);
dout.writeInt(count);
dout.writeInt(counter);
dout.flush();
} while(true);
} catch (Exception e) {
System.err.println(e.getMessage());
}
}
}