우선 Java (약 1 주일)에 익숙하지 않고 약간의 내용과 약간 혼동됩니다. 기본적으로 부울이 다음과 같은지 확인하려고합니다. 실제로 올 때 다음 스레드를 시작 사실, 그래서 여기에if 문 안에서 실행하십시오.
package apackage;
import java.util.Scanner;
public class Threads2 {
public static void main(String args[]){
Scanner scanner = new Scanner(System.in);
String selection;
System.out.println("Input one of the following answers for which timer you would like to start:");
System.out.println("Dragon, Baron, RedBuffNeutral, BlueBuffNeutral, RedBuffEnemy & BlueBuffEnemy");
selection = scanner.next();
if (selection.equalsIgnoreCase("dragon")){
boolean dragon = true;
Thread t1 = new Thread(new Threads("Dragon", "THREAD1"));
t1.start();
}else if (selection.equalsIgnoreCase("baron")){
Thread t2 = new Thread(new Threads("Baron", "THREAD2"));
t2.start();
}else if (selection.equalsIgnoreCase("redbuffneutral")){
Thread t3 = new Thread(new Threads("Red Buff Neutral", "THREAD3"));
t3.start();
}else if (selection.equalsIgnoreCase("bluebuffneutral")){
Thread t4 = new Thread(new Threads("Blue Buff Neutral", "THREAD4"));
t4.start();
}else if (selection.equalsIgnoreCase("redbuffenemy")){
Thread t5 = new Thread(new Threads("Red Buff Enemy", "THREAD5"));
t5.start();
}else if (selection.equalsIgnoreCase("bluebuffenemy")){
Thread t6 = new Thread(new Threads("Blue Buff Enemy", "THREAD6"));
t6.start();
}else{
System.out.println("You inputted an incorrect answer, please choose from the following next time:");
System.out.println("Dragon, Baron, RedBuffNeutral, BlueBuffNeutral, RedBuffEnemy & BlueBuffEnemy");
}
}
}
및
package apackage;
import java.util.Random;
public class Threads implements Runnable{
String name;
String text;
int time = 999;
int RedBuffNeutral, BlueBuffNeutral, RedBuffEnemy, BlueBuffEnemy = 300000;
int Dragon = 360000;
int Baron = 420000;
Random r = new Random();
public Threads(String x, String z){
text = z;
name = x;
}
if (dragon = true)
public void run(){
try{
System.out.printf("%s is dead for %d\n", name, Dragon);
Thread.sleep(Dragon);
System.out.printf("%s has respawned!\n", name);
}catch(InterruptedException exception){
System.out.printf("An error has occured in %s", name);
}
}
}
}
내가 첫 번째 클래스에 문제가없는 오전 (BTW 나는 두 개의 클래스를 사용하고 있습니다) 내 코드, 그것은이다 스레드를 실행하면 문제가 생길 때 실제로 어떻게해야하는지 실마리가 없으며 두 번째 클래스의 16 번째 줄에서 오류가 발생합니다. s : 토큰 "if"에 대한 구문 오류, 잘못된 AnnotationName 도움을 주시면 감사하겠습니다. 내 문제에 대한 자세한 정보를 원하시면 그냥 물어보십시오! 감사합니다 :
if (dragon = true)
public void run(){ /* etc */
당신은 당신이 생각하는 말을 의미하지 않는다 : D
'dragon = true'는 조건문이 아니라 할당 임 – Coffee
문제가있는 if 문도 클래스의 메서드 범위를 벗어난 것으로 보입니다. – user3062946
'dragon'이 선언 된 곳을 보지 못했습니다. 다른 버그가있을 수 있다고 생각합니다. – Coffee