Closed. This question is not reproducible or was caused by typos。它当前不接受答案。
                            
                        
                    
                
            
                    
                
                        
                            
                        
                    
                        
                            想改善这个问题吗? Update the question,所以它是on-topic,用于堆栈溢出。
                        
                        在8个月前关闭。
                    
                
        

我正在尝试建立一个简单的平衡系统,该系统可以用诸如getbalance,setbalance之类的太多元素进行控制,但是问题是现在我正在尝试通过用户输入来实现setbalance,但是我今天才启动Java,例如我将使用随机生成的数字设置余额。我得到的问题是语法错误插入。
我的代码:

package javatest;

import java.util.Random;

public class testas {

    public static void main(String[] args) {
        // New coding started *2019/09.08
        //TODO *RANDOM MATCH ID.
        //TODO *Random sk (Dice)

        //TODO Bets on dice
        Random MatchID = new Random();
        int Matchoidas = MatchID.nextInt(999999999);
        //Convert Integer to string
        String mch1 = Integer.toString(Matchoidas);
        mch1 = "ID"+ mch1 + "sf";
        Random sk = new Random();
        int ska = sk.nextInt(6);
        ska += 1;
        int value = ska;
        System.out.println("Match: " + mch1 +" You rolled: " + ska + "\nYour ballance : " + balance);

    }

    private static double balance;
    private int accnr;

    public double setbalance(value) {

        balance = value;
    }

    public double getbalance() {

        return balance;
    }

    public int getaccnr() {

            return accnr;
        }

    }


*在Setbalance行中编辑问题。

最佳答案

要使其编译,您需要声明参数value的类型并返回某些内容,因为返回类型为double

  public double setbalance(double value) {
      return balance = value;
  }


虽然,标准的二传手看起来像

  public void setBalance(double value) {
      balance = value;
  }

08-06 04:18