|
// Raqamlar yig'indisini hisoblash
|
bet | 3/8 | Sana | 18.05.2024 | Hajmi | 0,9 Mb. | | #242341 |
Bog'liq 7ish00 // Raqamlar yig'indisini hisoblash PrintWriter output = new PrintWriter(clientSocket.getOutputStream(), true); for (int son : sonlar) { int yigindi = sumOfDigits(son); output.println(yigindi); } } } } }
// Raqamlar yig'indisini hisoblash uchun yordamchi metod private static int sumOfDigits(int number) { int sum = 0; while (number != 0) { sum += number % 10; number /= 10;
package javafx; import java.io.*; import java.net.*; import java.util.*;
public class Client { public static void main(String[] args) throws IOException { // Serverga bog'lanish try (Socket socket = new Socket("localhost", 5000)) { // Klientdan N ta sonni olish BufferedReader userInput = new BufferedReader(new InputStreamReader(System.in)); System.out.print("Nechta son kiritmoqchisiz (N): "); int N = Integer.parseInt(userInput.readLine());
List sonlar = new ArrayList<>(); for (int i = 0; i < N; i++) { System.out.print((i + 1) + "-sonni kiriting: "); sonlar.add(Integer.parseInt(userInput.readLine())); }
// Serverga sonlarni yuborish PrintWriter output = new PrintWriter(socket.getOutputStream(), true); output.println(N); // Birinchi bo'lib N ni yuboramiz for (int son : sonlar) { output.println(son); // Har bir sonni alohida yuboramiz }
// Serverdan javobni qabul qilish BufferedReader input = new BufferedReader(new InputStreamReader(socket.getInputStream())); List yigindilar = new ArrayList<>(); for (int i = 0; i < N; i++) { yigindilar.add(Integer.parseInt(input.readLine())); }
|
| |