谁能给我出一道JAVA编程基础的测试题?有没有双重答案的?把答案也给我写上,再给一道C语言的题和答案,谢谢了
- 提问者网友:献世佛
- 2021-04-13 05:11
- 五星知识达人网友:渡鹤影
- 2021-04-13 06:07
x你好 我来回答你的问题
JAVE编程题我这边暂时没有 但是网上应该有很多 关于C语言的编程题 我给你一道十分基础的题目
以下为手打
输入一个带符号的短整形数 输入该数的位数
程序清单如下:
voin main()
{ int x m;
scanf("%d",&x);
if (x<0)x=-x
if (x<10) m=1
else if (x<100) m=2
else if (x<1000) m=3
else if (x<10000) m=4
else m=5;
printf("m=%d\n",m);
}
这个是很基础的题目 上面的空格因为为了显示更容易理解所以这样 真正在编程时 空格请自己掌握
因为正在学C 不了解JAVE 则不评论
希望能解决你的问题哦 要是不满意 希望追问哦 O(∩_∩)O~
热播广告
问问团队 正在删除 (用心回答每个问题) 团长 YOU
(正在删除)问问团队
团队地址为: http://wenwen.soso.com/t/TeamHome.e?sp=398398
ID 94799115
- 1楼网友:行雁书
- 2021-04-13 07:27
Java基础??恩;先吧尚学堂的那个坦克大战;和聊天做出来。。那么你的JavaSe基础就差不多了应该。
下面是哪个聊天:
服务器端:
import java.io.*; import java.net.*; import java.util.*;
public class ChatServer { boolean started = false; ServerSocket ss = null; List<Client> clients = new ArrayList<Client>(); public static void main(String[] args) { new ChatServer().start(); } public void start() { try { ss = new ServerSocket(8888); started = true; } catch (BindException e) { System.out.println("端口使用中...."); System.out.println("请关掉相关程序并重新运行服务器!"); System.exit(0); } catch (IOException e) { e.printStackTrace(); } try { while(started) { Socket s = ss.accept(); Client c = new Client(s); System.out.println("a client connected!"); new Thread(c).start(); clients.add(c); //dis.close(); } } catch (IOException e) { e.printStackTrace(); } finally { try { ss.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } class Client implements Runnable { private Socket s; private DataInputStream dis = null; private DataOutputStream dos = null; private boolean bConnected = false; public Client(Socket s) { this.s = s; try { dis = new DataInputStream(s.getInputStream()); dos = new DataOutputStream(s.getOutputStream()); bConnected = true; } catch (IOException e) { e.printStackTrace(); } } public void send(String str) { try { dos.writeUTF(str); } catch (IOException e) { clients.remove(this); System.out.println("对方退出!"); //e.printStackTrace(); } } public void run() { try { while(bConnected) { String str = dis.readUTF(); System.out.println(str); for(int i=0; i<clients.size(); i++) { Client c = clients.get(i); c.send(str); //System.out.println(" a string send !"); } } } catch (EOFException e) { System.out.println("Client closed!"); } catch (IOException e) { e.printStackTrace(); } finally { try { if(dis != null) dis.close(); if(dos != null) dos.close(); if(s != null) { s.close(); //s = null; } } catch (IOException e1) { e1.printStackTrace(); } } } } }
客户端:
import java.awt.*; import java.awt.event.*; import java.io.*; import java.net.*;
public class ChatClient extends Frame { Socket s = null; DataOutputStream dos = null; DataInputStream dis = null; private boolean bConnected = false;
TextField tfTxt = new TextField();
TextArea taContent = new TextArea(); Thread tRecv = new Thread(new RecvThread());
public static void main(String[] args) { new ChatClient().launchFrame(); }
public void launchFrame() { setLocation(400, 300); this.setSize(300, 300); add(tfTxt, BorderLayout.SOUTH); add(taContent, BorderLayout.NORTH); pack(); this.addWindowListener(new WindowAdapter() {
@Override public void windowClosing(WindowEvent arg0) { disconnect(); System.exit(0); } }); tfTxt.addActionListener(new TFListener()); setVisible(true); connect(); tRecv.start(); } public void connect() { try { s = new Socket("127.0.0.1", 8888); dos = new DataOutputStream(s.getOutputStream()); dis = new DataInputStream(s.getInputStream()); System.out.println("connected!"); bConnected = true; } catch (UnknownHostException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } public void disconnect() { try { dos.close(); dis.close(); s.close(); } catch (IOException e) { e.printStackTrace(); } } private class TFListener implements ActionListener {
public void actionPerformed(ActionEvent e) { String str = tfTxt.getText().trim(); //taContent.setText(str); tfTxt.setText(""); try { //System.out.println(s); dos.writeUTF(str); dos.flush(); //dos.close(); } catch (IOException e1) { e1.printStackTrace(); } } } private class RecvThread implements Runnable {
public void run() { try { while(bConnected) { String str = dis.readUTF(); //System.out.println(str); taContent.setText(taContent.getText() + str + '\n'); } } catch (SocketException e) { System.out.println("退出了,bye!"); } catch (EOFException e) { System.out.println("退出,bye - bye!"); } catch (IOException e) { e.printStackTrace(); } } } }
- 2楼网友:詩光轨車
- 2021-04-13 06:14
JAVA基础测试题(单选,多选,有答案)很全
http://www.java2000.net/selftest/