Advertisement
didito33

Server

Nov 28th, 2021
30
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.51 KB | None | 0 0
  1. package Socket;
  2. import java.io.IOException;
  3. import java.io.PrintStream;
  4. import java.net.ServerSocket;
  5. import java.net.Socket;
  6. import java.util.Scanner;
  7. public class Server {
  8. public static void main(String[] args) throws IOException {
  9. int number;
  10. ServerSocket server = new ServerSocket(1211);
  11. Socket socket = server.accept();
  12. Scanner scan = new Scanner(socket.getInputStream());
  13. number = scan.nextInt();
  14. PrintStream printout = new PrintStream(socket.getOutputStream());
  15. if(number > 0){
  16. printout.println("The number is positive.");
  17. if ((number % 2) == 0) {
  18. printout.println("It also is an even one.");
  19. if(number%5 == 0)
  20. printout.println("As well as it can be divided by 5.");
  21. } else {
  22. if(number%5 == 0)
  23. printout.println("As well as it can be divided by 5.");
  24.  
  25. printout.println("It also is an odd one.");
  26. }
  27. }
  28. else{
  29. printout.println("The number is negative.");
  30. if ((number % 2) == 0) {
  31. printout.println("It also is an even one.");
  32. if(number%5 == 0)
  33. printout.println("As well as it can be divided by 5");
  34. }
  35. else{
  36. printout.println("It also is an odd one.");
  37. if(number%5 == 0)
  38. printout.println("As well as it can be divided by 5");
  39. }
  40. }
  41. server.close();
  42. scan.close();
  43. }
  44. }
  45.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement