생활
진수변환 2진수로 변환은했는데 8진수 16진수에서막히네요;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.util.Scanner;
public class LabelAndTextTest extends JFrame {
JTextField tf = new JTextField(10);
JTextField ta = new JTextField(20);
JTextField tb = new JTextField(20);
JTextField tc = new JTextField(20);
JButton b = new JButton("변환");
public LabelAndTextTest(String title){
super(title);
this.add(new JLabel("변환할 십진수를 입력하시오."));
this.add(tf);
this.add(b);
this.add(new JLabel("변환된 2진수 입니다. "));
this.add(new JLabel("변환된 8진수 입니다. "));
this.add(new JLabel("변환된 16진수 입니다. "));
this.add(ta);
this.add(tb);
this.add(tc);
b.addActionListener(new OKAction());
}
public static void main(String[] args){
LabelAndTextTest f = new LabelAndTextTest("LabelAndTextTest");
f.setSize(320,240);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setLayout(new FlowLayout());
f.setVisible(true);
}
class OKAction implements ActionListener{
public void actionPerformed(ActionEvent e){
int i = Integer.parseInt(tf.getText());
int Count = 0;
int temp = i;
while(true){
temp = temp/2;
if(temp==0)
break;
else
Count++;
}
char []Arr2 = new char[Count+1];
temp = i;
for(;temp>=1;Count--){
int temp2;
temp2 = temp%2;
Arr2[Count] = 48;
Arr2[Count] += temp2;
temp = temp/2;
}
String result = new String(Arr2);
ta.setText(result);
}
}
}
여기서 리절트값으로 8진수로 16진수로바꾸려는데
자꾸에러가나네요 ㅡ,.ㅡ;
리절트값으로 변환하는거 가능하지않나여?
아직 답변이 없어요.