내 문자열을 println 할 때 문제가 발생합니다. 나는 전체 println이 "BAR, ORANGE, PLUM"과 같은 것을 읽길 원합니다. 문자열이 println 문과 통신하지 않는 것 같습니다. 나는 아주 새로운 자바이고 나는 극도로 길을 잃었으므로 당신의 제안을 매우 기본적으로 설명하십시오. 나는 정말로 대답뿐 아니라 설명을 주셔서 감사하게 생각합니다. 다시 그런 실수를하지 마십시오. 시간 내 주셔서 감사합니다. 가시성이 코드 블록으로 제한되도록해결되지 않은 문자열이있는 Println
/*
* This program will simulate playing a slot machine.
* It will provide instructions to the user with an initial stake of $50 and then let the user play until either the money runs out or the player quits.
* Author: Zac Saunders
* Version: 1.3
*/
import acm.program.*;
import java.awt.*;
import acm.util.RandomGenerator;
public class SlotMachine_V2 extends GraphicsProgram {
RandomGenerator rgen = new RandomGenerator();
public void run(){
waitForClick();
rollWheels();
}
public void rollWheels(){
Wheel_1();
Wheel_2();
Wheel_3();
println("You rolled:"+aa, + bb, +cc"");
run();
}
public void Wheel_1(){
int a = rgen.nextInt(1, 6);
if(a == 1){//BAR//
String aa =(" BAR, ");
}else if(a == 2){//BELL//
String aa =(" BELL, ");
}else if(a == 3){//PLUM//
String aa =(" PLUM, ");
}else if(a == 4){//ORANGE//
String aa =(" ORANGE, ");
}else if(a == 5){//CHERRY//
String aa =(" CHERRY, ");
}else if(a == 6){//DASH (-)//
String aa =(" -, ");
}
}
public void Wheel_2(){
int b = rgen.nextInt(1, 6);
if(b == 1){//BAR//
String bb =("BAR, ");
}else if(b == 2){//BELL//
String bb =("BELL, ");
}else if(b == 3){//PLUM//
String bb =("PLUM, ");
}else if(b == 4){//ORANGE//
String bb =("ORANGE, ");
}else if(b == 5){//CHERRY//
String bb =("CHERRY, ");
}else if(b == 6){//DASH (-)//
String bb =("-, ");
}
}
public void Wheel_3(){
int c = rgen.nextInt(1, 6);
if(c == 1){//BAR//
String cc =("and BAR");
}else if(c == 2){//BELL//
String cc =("and BELL");
}else if(c == 3){//PLUM//
String cc =("and PLUM");
}else if(c == 4){//ORANGE//
String cc =("and ORANGE");
}else if(c == 5){//CHERRY//
String cc =("and CHERRY");
}else if(c == 6){//DASH (-)//
String cc =("and -");
}
}
}
주위에있는 쉼표를 넣지 마십시오 당신의'끈'의 주위에. 부디. –
왜 같은 문자열을 반복해서 선언하고 있습니까? – iWumbo
임의의 Generator 세트가 휠을 결정하면 그 String은 aa 또는 bb 또는 cc가됩니다. 이것을하기위한 더 좋은 방법이 있습니까? – TheZac2613