byte color
으로 전환하면 색상을 유지해야합니다 (예 : 빨간색 또는 녹색). show()
방법의 결과 분류하고이 색상을 설명하기 위해 스위치를 사용해야합니다 (같은 다른 변종 : 빨강 - 파랑, 녹색 - 빨강 등) *은 좋은 방법에문자열 및 문자열을 바이트
public class Candy {
//fields
int quantity;
byte color;
double price;
//constructor
Candy(int quantity, byte color, double price)
{
this.quantity = quantity;
this.color = color;
this.price = price;
}
//this method have to show class fields
public void show(String colors)
{
switch(color)
{
case 1: colors = "red";
case 2: colors = "green";
case 3: colors = "blue";
}
//tried to convert
//String red = "Red";
//byte[] red1 = red.getBytes();
//String green = "Green";
//byte[] green1 = green.getBytes();
public static void main(String[] args)
{
//program
}
}
가 나는 건가요 열거 사용할 수 없습니다? 문자열을 바이트로 유지하는 방법? 감사합니다
는
당신이 한 바이트에서 이러한 세 가지 색상의 모든 가능한 조합을 인코딩 뜻 이것은 당신의
show()
방법? – bellum귀하의 질문은 무엇입니까? –
@bellum 해당 바이트 (색상)의 모든 단일 비트는 하나의 색상을 저장해야합니다. – Fastkowy