-4

Нашел в инете код но он выдает ошибку:

Error:(73, 6) java: reached end of file while parsing

package com.company;

public class CpuSpecification {

public static int getLogicalNumberCPUCores(){
    int cores = Runtime.getRuntime().availableProcessors();
    return cores;
}
public static int getPhysycalNumberCPUCores() {
    OSValidator osValidator = new OSValidator();
    String command = "";
    if(osValidator.isMac()){
        command = "sysctl -n machdep.cpu.core_count";
    }else if(osValidator.isUnix()){
        command = "lscpu";
    }else if(osValidator.isWindows()){
        command = "cmd /C WMIC CPU Get /Format:List";
    }
    Process process = null;
    int numberOfCores = 0;
    int sockets = 0;
    try {
        if(osValidator.isMac()){
            String[] cmd = { "/bin/sh", "-c", command};
            process = Runtime.getRuntime().exec(cmd);
        }else{
            process = Runtime.getRuntime().exec(command);
        }
    } catch (IOException e) {
        e.printStackTrace();
    }

    BufferedReader reader = new BufferedReader(
            new InputStreamReader(process.getInputStream()));
    String line;

    try {
        while ((line = reader.readLine()) != null) {
            if(osValidator.isMac()){
                numberOfCores = line.length() > 0 ? Integer.parseInt(line) : 0;
            }else if (osValidator.isUnix()) {
                if (line.contains("Core(s) per socket:")) {
                    numberOfCores = Integer.parseInt(line.split("\\s+")[line.split("\\s+").length - 1]);
                }
                if(line.contains("Socket(s):")){
                    sockets = Integer.parseInt(line.split("\\s+")[line.split("\\s+").length - 1]);
                }
            } else if (osValidator.isWindows()) {
                if (line.contains("NumberOfCores")) {
                    numberOfCores = Integer.parseInt(line.split("=")[1]);
                }
            }
        }
    } catch (IOException e) {
        e.printStackTrace();
    }
    if(osValidator.isUnix()){
        return numberOfCores * sockets;
    }
    return numberOfCores;
}
1
  • 1
    Вы не код бездумно копируйте, а учебники по джаве читайте
    – andreymal
    23 дек 2018 в 11:03

1 ответ 1

2

Вы забыли скобки в конце! .

5
  • 1
    Ну написал же человек, "нашел в инете код", чего удивляться?) 23 дек 2018 в 10:41
  • 1
    Как вообще можно тогда что то писать 23 дек 2018 в 10:44
  • не является ответом 23 дек 2018 в 13:08
  • 1
    @hUuueeeyy то что человек нашел код это хорошо. Еще бы он начал разбираться что там написано. И тогда не будет таких тупых вопросов.
    – Tsyklop
    23 дек 2018 в 13:54
  • 1
    @michael_best какой вопрос - такой и ответ.
    – Tsyklop
    23 дек 2018 в 13:55

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge you have read our privacy policy.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.