求java题答案!!!
1个回答
展开全部
6-1
新亲亲斤
6-2
Hello!I love JAVA.
6-3
s=180
7-1
public class Topic7_1 extends Applet implements KeyListener
{
private JTextField jt1, jt2;
public void init()
{
jt1 = new JTextField(20);
jt2 = new JTextField(20);
add(jt1);
add(jt2);
jt1.addKeyListener(this);
}
@Override
public void keyPressed(KeyEvent e)
{
if (e.getKeyCode() == KeyEvent.VK_ENTER)
{
try
{
int inS = Integer.parseInt(jt1.getText());
jt2.setText(inS * inS + "");
} catch (Exception e2)
{
}
}
}
@Override
public void keyReleased(KeyEvent arg0)
{
// TODO Auto-generated method stub
}
@Override
public void keyTyped(KeyEvent arg0)
{
// TODO Auto-generated method stub
}
}
7-2
public class TopicServer7_2
{
public static void main(String[] args) throws IOException
{
ServerSocket ss = new ServerSocket(8888);
Socket socket = ss.accept();
InputStream is = socket.getInputStream();
OutputStream os = socket.getOutputStream();
byte[] buffer = new byte[200];
int length = 0;
length = is.read(buffer);
String str = new String(buffer, 0, length);
// 收到的数据 5,4,3是字符 转为我们能计算的
String[] str3 = str.split(",");
// 面积公式 (底*高)/2
int area = (Integer.parseInt(str3[1]) * Integer.parseInt(str3[2]) / 2);
os.write((area + "").getBytes());
is.close();
os.close();
socket.close();
}
}
public class TopicClient7_2
{
static Logger logger = LoggerFactory.getLogger(TopicClient7_2.class);
public static void main(String[] args) throws UnknownHostException, IOException
{
Socket socket = new Socket("127.0.0.1", 8888);
OutputStream os = socket.getOutputStream();
// 三边形(简单的举一个例子,实际不会这样传)
os.write("5,4,3".getBytes());
InputStream is = socket.getInputStream();
byte[] buffer = new byte[200];
int length = is.read(buffer);
String str = new String(buffer, 0, length);
System.out.println("面积:" + str);
is.close();
os.close();
socket.close();
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询