Advertisement
Guest User

Untitled

a guest
May 22nd, 2018
207
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.95 KB | None | 0 0
  1. import java.net.*;
  2. import java.io.*;
  3. public class Server_D{
  4.     public static void main(String[] args){
  5.         try{
  6.             ServerSocket server = new ServerSocket(8888);
  7.             Socket client = null;
  8.             BufferedReader in;
  9.             System.out.println("Server pronto \n");
  10.             Integer conta = 0;
  11.             while(true){
  12.                 client = server.accept();
  13.                 in = new BufferedReader(new InputStreamReader(client.getInputStream()));
  14.                 String mex = in.readLine();
  15.                 System.out.println(mex+"\n");
  16.                 PrintWriter out = new PrintWriter(client.getOutputStream(), true);
  17.                 conta = conta_maiuscole(mex); // variabile intera
  18.                 out.println(conta.toString()); //tostring
  19.                 client.close();
  20.             }  
  21.         }
  22.         catch (Exception e){
  23.             e.printStackTrace();
  24.         }
  25.     }
  26.  
  27.     public static int conta_maiuscole(String str){
  28.         int count = 0;
  29.         for(int i=0; i<str.length(); i++){
  30.             if ( Character.isUpperCase(str.charAt(i)) ) count++;
  31.         }
  32.         return count;
  33.     }
  34.    
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement