小编Tim*_*der的帖子

覆盖抽象方法TimerTask.Run()

我在覆盖从TimerTask类运行的方法时遇到问题.

这是我的代码:

public class PGameCore 
{

    Toolkit toolKit;
    Timer   timer;

    public PGameCore(int clockIntervalInSeconds)
    {
        timer = new Timer();
        timer.schedule(new CoreTimer(), 1000 * clockIntervalInSeconds);
    }

    class CoreTimer extends TimerTask
    {
            public void Run()
            {
                System.out.println("BEEEP :)");
                toolKit.beep();
            }
    }

}
Run Code Online (Sandbox Code Playgroud)

问题在于:

class CoreTimer extends TimerTask
Run Code Online (Sandbox Code Playgroud)

我正在使用Netbeans.它说:"PGameCore.CoreTimer不是抽象的,不会覆盖TimerTask中的抽象方法run()."

java abstract-class overriding

0
推荐指数
1
解决办法
457
查看次数

java中链表代码的意外结果

以下代码编译并执行,没有任何错误或警告.但给出了意想不到的结果.

代码:

import java.util.LinkedList;
import java.util.Scanner;

//defining a custom data-type (class)
class LLObj{
    static int NodeInt;
    static char NodeChar;

    LLObj(int x, char y){
        NodeInt = x;
        NodeChar = y;
    }
}

class LLexp{

    static LinkedList<LLObj> list = new LinkedList<>();

    public static void main(String[] args){

        list.addLast(new LLObj(5,'c'));

        System.out.println(list.get(0).NodeInt);
        System.out.println(list.get(0).NodeChar);

        list.addLast(new LLObj(7,'h'));

        System.out.println(list.get(0).NodeInt);
        System.out.println(list.get(0).NodeChar);
        System.out.println(list.get(1).NodeInt);
        System.out.println(list.get(1).NodeChar);
    }
}
Run Code Online (Sandbox Code Playgroud)

预期产出 -

5
c
5
c
7
h

获得的输出 -

5
c
7
h
7
h

  1. 为什么会这样?
  2. 我如何得到预期的结果?

java

0
推荐指数
1
解决办法
286
查看次数

将非连续值的int数组拆分为几个连续的int数组

int[] big = {1,2,3,5,11,12,13,25,26};
Run Code Online (Sandbox Code Playgroud)

doSomething将连续的元素组合在一起如何将"大"分成这个:

{{1,2,3},{5},{11,12,13},{25,26}}
Run Code Online (Sandbox Code Playgroud)

我已经开始使用这段代码:

public List<Integer> getR(){
    Integer[] big = {1,2,3,5,11,12,13,25,26};
    List<Integer> a = new ArrayList<Integer>();
    for(int i=0;i<big.length;i++){
        if(big[i]==big[i+1]-1){
            continue;
        }else{
            //...
        }
        //...
    }
    //...
}
Run Code Online (Sandbox Code Playgroud)

java

0
推荐指数
1
解决办法
1024
查看次数

在Python中,字符串被视为列表吗?

我只是好奇字符串是否被视为列表。

python

-2
推荐指数
1
解决办法
282
查看次数

Java Dice滚动程序,为什么不滚动1?

为我正在制作的项目创建了这个程序,但我似乎无法弄清楚为什么它从未在结果中给出任何1.我在这里踢自己因为它可能很简单.

为了清楚起见:程序必须滚动两个单独的模具36k次并显示结果.

import java.util.Random; //Going to need this

public class Dicerolling { //Start Class



public static void main( String[] args) 
{ //Start of Main
    Random randomNumbers = new Random(); // Generates random numbers
    int[] array = new int[ 13 ]; // Declares the array
    int dice1 = 0;
    int dice2;
    int total;

    //Roll the die 36,000 times
    for ( int roll = 1; roll <=36000; roll++ )
        dice1 = 1 + randomNumbers.nextInt ( 6 );
        dice2 = 1 + randomNumbers.nextInt …
Run Code Online (Sandbox Code Playgroud)

java

-4
推荐指数
1
解决办法
465
查看次数

标签 统计

java ×4

abstract-class ×1

overriding ×1

python ×1