求大神救,能帮看看Java代码吗?

各路大神好,我是一个编程小小白,所以我估计所提的问题也会很小白,万望各位大神不要鄙视不要生气不要吐槽,我正努力地向各位靠近。

想请大神帮我看看,下面的代码为什么是错的勒?我是真的真的不知道哇。
PS:我有看过CSDN上的文章,但不知道这里能不能这样直接作为问题发表出来,若是不可以,还望告知,我会马上删除的。

题目是

计算机内部用二进制来表达所有的值。一个十进制的数字,比如18,在一个32位的计算机内部被表达为00000000000000000000000000011000。可以看到,从左边数过来,在第一个1之前,有27个0。我们把这些0称作前导的零。


任务是写一个程序,输入一个整数,输出在32位二进制表达下它前导的零的个数。如输入256,输出23.

import java.util.Scanner;
public class Javafirst {
 public static void main(String[] args) {
  // TODO Auto-generated method stub
  Scanner in = new Scanner(System.in);
  int nummer = in.nextInt();
  int amount = 0;
  int []a = new int[32];
  int i = 0;
  int j = 31;
     int Quantity = 0;
     while(nummer >= 2) {
   a[i] = nummer % 2;
   nummer = nummer / 2;
   i++;
  }
    
     while(j >= 0) {
      
      if( a[j] == 1) {
       break;
      }
      j--;
    }
  Quantity = 32 - j;
  System.out.println(Quantity);
 }
}

大神看看这行代码啥意思?

12-27

这代码有点看不懂,rn[color=#FF0000]VAR_DECLSPEC PayloadType payload_type_h264;[/color]rn中的payload_type_h264代表啥数字?rnrn[code=c]rnrn#ifndef PAYLOADTYPE_Hrn#define PAYLOADTYPE_Hrn#include rnrn#ifdef __cplusplusrnextern "C"rn#endifrnrn/* flags for PayloadType::flags */rnrn#define PAYLOAD_TYPE_ALLOCATED (1)rn /* private flags for future use by ortp */rn#define PAYLOAD_TYPE_PRIV1 (1<<1)rn#define PAYLOAD_TYPE_PRIV2 (1<<2)rn#define PAYLOAD_TYPE_PRIV3 (1<<3)rn /* user flags, can be used by the application on top of oRTP */rn#define PAYLOAD_TYPE_USER_FLAG_0 (1<<4)rn#define PAYLOAD_TYPE_USER_FLAG_1 (1<<5)rn#define PAYLOAD_TYPE_USER_FLAG_2 (1<<6)rn /* ask for more if you need*/rnrn#define PAYLOAD_AUDIO_CONTINUOUS 0rn#define PAYLOAD_AUDIO_PACKETIZED 1rn#define PAYLOAD_VIDEO 2rn#define PAYLOAD_TEXT 4rn#define PAYLOAD_OTHER 3 /* ?? */rnrnstruct _PayloadTypernrn int type; /**< one of PAYLOAD_* macros*/rn int clock_rate; /**< rtp clock rate*/rn char bits_per_sample; /* in case of continuous audio data */rn char *zero_pattern;rn int pattern_length;rn /* other useful information for the application*/rn int normal_bitrate; /*in bit/s */rn char *mime_type; /**flags|=((int)flag)rn#define payload_type_unset_flag(pt,flag) (pt)->flags&=(~(int)flag)rn#define payload_type_get_flags(pt) (pt)->flagsrnrnrnORTP_PUBLIC PayloadType *payload_type_new(void);rnORTP_PUBLIC PayloadType *payload_type_clone(PayloadType *payload);rnORTP_PUBLIC char *payload_type_get_rtpmap(PayloadType *pt);rnORTP_PUBLIC void payload_type_destroy(PayloadType *pt);rnORTP_PUBLIC void payload_type_set_recv_fmtp(PayloadType *pt, const char *fmtp);rnORTP_PUBLIC void payload_type_set_send_fmtp(PayloadType *pt, const char *fmtp);rnORTP_PUBLIC void payload_type_append_recv_fmtp(PayloadType *pt, const char *fmtp);rnORTP_PUBLIC void payload_type_append_send_fmtp(PayloadType *pt, const char *fmtp);rnrn#define payload_type_get_bitrate(pt) ((pt)->normal_bitrate)rn#define payload_type_get_rate(pt) ((pt)->clock_rate)rn#define payload_type_get_mime(pt) ((pt)->mime_type)rnrnORTP_PUBLIC bool_t fmtp_get_value(const char *fmtp, const char *param_name, char *result, size_t result_len);rnrn#define payload_type_set_user_data(pt,p) (pt)->user_data=(p)rn#define payload_type_get_user_data(pt) ((pt)->user_data)rnrnrn/* some payload types */rn/* audio */rnVAR_DECLSPEC PayloadType payload_type_pcmu8000;rnVAR_DECLSPEC PayloadType payload_type_pcma8000;rnVAR_DECLSPEC PayloadType payload_type_pcm8000;rnVAR_DECLSPEC PayloadType payload_type_l16_mono;rnVAR_DECLSPEC PayloadType payload_type_l16_stereo;rnVAR_DECLSPEC PayloadType payload_type_lpc1016;rnVAR_DECLSPEC PayloadType payload_type_g729;rnVAR_DECLSPEC PayloadType payload_type_g7231;rnVAR_DECLSPEC PayloadType payload_type_g7221;rnVAR_DECLSPEC PayloadType payload_type_g726_40;rnVAR_DECLSPEC PayloadType payload_type_g726_32;rnVAR_DECLSPEC PayloadType payload_type_g726_24;rnVAR_DECLSPEC PayloadType payload_type_g726_16;rnVAR_DECLSPEC PayloadType payload_type_aal2_g726_40;rnVAR_DECLSPEC PayloadType payload_type_aal2_g726_32;rnVAR_DECLSPEC PayloadType payload_type_aal2_g726_24;rnVAR_DECLSPEC PayloadType payload_type_aal2_g726_16;rnVAR_DECLSPEC PayloadType payload_type_gsm;rnVAR_DECLSPEC PayloadType payload_type_lpc;rnVAR_DECLSPEC PayloadType payload_type_lpc1015;rnVAR_DECLSPEC PayloadType payload_type_speex_nb;rnVAR_DECLSPEC PayloadType payload_type_speex_wb;rnVAR_DECLSPEC PayloadType payload_type_speex_uwb;rnVAR_DECLSPEC PayloadType payload_type_ilbc;rnVAR_DECLSPEC PayloadType payload_type_amr;rnVAR_DECLSPEC PayloadType payload_type_amrwb;rnVAR_DECLSPEC PayloadType payload_type_truespeech;rnVAR_DECLSPEC PayloadType payload_type_evrc0;rnVAR_DECLSPEC PayloadType payload_type_evrcb0;rnVAR_DECLSPEC PayloadType payload_type_silk_nb; rnVAR_DECLSPEC PayloadType payload_type_silk_mb;rnVAR_DECLSPEC PayloadType payload_type_silk_wb;rnVAR_DECLSPEC PayloadType payload_type_silk_swb;rnrn /* video */rnVAR_DECLSPEC PayloadType payload_type_mpv;rnVAR_DECLSPEC PayloadType payload_type_h261;rnVAR_DECLSPEC PayloadType payload_type_h263;rnVAR_DECLSPEC PayloadType payload_type_h263_1998;rnVAR_DECLSPEC PayloadType payload_type_h263_2000;rnVAR_DECLSPEC PayloadType payload_type_mp4v;rnVAR_DECLSPEC PayloadType payload_type_theora;rn[color=#FF0000]VAR_DECLSPEC PayloadType payload_type_h264;[/color]rnVAR_DECLSPEC PayloadType payload_type_x_snow;rnVAR_DECLSPEC PayloadType payload_type_jpeg;rnVAR_DECLSPEC PayloadType payload_type_vp8;rnrnVAR_DECLSPEC PayloadType payload_type_g722;rnrn/* text */rnVAR_DECLSPEC PayloadType payload_type_t140;rnVAR_DECLSPEC PayloadType payload_type_t140_red;rnrn/* non standard file transfer over UDP */rnVAR_DECLSPEC PayloadType payload_type_x_udpftp;rnrn/* telephone-event */rnVAR_DECLSPEC PayloadType payload_type_telephone_event;rnrn#ifdef __cplusplusrnrn#endifrnrn#endifrnrn[/code]

关于android socket通讯,求大神看看

11-13

写了个android与pc端通信的例子,pc端用的是mfc写的,做服务端。想实现以下功能:rnandroid填写完用户名和密码点击登录按钮,android把用户名和密码打包发给pc端,pc端收到后在发出一条消息给android,android收到并解析这条消息后启动一个新Activity。rn现在的情况是android能给PC发信息,PC端给android发信息收不到。rn这是android的源码:rnpackage com.example.sendtoserver;rnrnimport java.io.BufferedReader;rnimport java.io.BufferedWriter;rnimport java.io.IOException;rnimport java.io.InputStreamReader;rnimport java.io.OutputStreamWriter;rnimport java.net.Socket;rnimport java.net.UnknownHostException;rnrnrnimport android.os.Bundle;rnimport android.os.Message;rnimport android.os.StrictMode;rnimport android.app.Activity;rnimport android.content.Intent;rnimport android.util.Log;rnimport android.view.Menu;rnimport android.view.View;rnimport android.view.View.OnClickListener;rnimport android.widget.Button;rnimport android.widget.EditText;rnrnpublic class MainActivity extends Activityrnrn Socket socket=null;rn String ip="192.168.137.1";rn int port=8888;rn BufferedReader br=null;rn BufferedWriter bw=null;rn Button loginButton=null;rn EditText username=null;rn EditText password=null;rn ReceiveThread receThread=null;rn String receString=null;rn InitThread it=null;rn @Overridern protected void onCreate(Bundle savedInstanceState)rn rn super.onCreate(savedInstanceState);rn setContentView(R.layout.activity_main);rn setContentView(R.layout.activity_main);rn rn loginButton=(Button)this.findViewById(R.id.login);rn loginButton.setOnClickListener(new OnClickListener() rn rn @Overridern public void onClick(View arg0) rn rn // TODO Auto-generated method stubrn if(bw!=null)rn rn tryrn rn bw.write("/Cmd Login /username "+username.getText().toString()+" /password "+password.getText().toString()+" /");rn bw.flush();rn rn catch (IOException e)rn rn // TODO Auto-generated catch blockrn e.printStackTrace();rn rn rn rn );rn username=(EditText)this.findViewById(R.id.username);rn password=(EditText)this.findViewById(R.id.password);rn rn it=new InitThread();rn it.start();rn receThread=new ReceiveThread();rn receThread.start();rn rn class InitThread extends Threadrn rnrn @Overridern public void run() rn rn // TODO Auto-generated method stubrn super.run();rn tryrn rn socket=new Socket(ip,port);rn bw=new BufferedWriter(new OutputStreamWriter(socket.getOutputStream()));rn br=new BufferedReader(new InputStreamReader(socket.getInputStream()));rn rn catch (UnknownHostException e)rn rn // TODO Auto-generated catch blockrn e.printStackTrace();rn rn catch (IOException e)rn rn // TODO Auto-generated catch blockrn e.printStackTrace();rn rn rn rn rn class ReceiveThread extends Threadrn rnrn @Overridern public void run()rn rn // TODO Auto-generated method stubrn super.run();rn if(br!=null)rn rn try rn rn int count=0;rn char[] buffer=null;rn while(true)rn rn if((count=br.read(buffer))>0)rn rn break;rn rn rn receString=buffer.toString();rn String[] cmd=parse(receString);rn Intent intent=new Intent();rn intent.putExtra("id",(cmd[2].split(" "))[1]);rn intent.putExtra("queueId",(cmd[3].split(" "))[1]);rn intent.putExtra("queueName",(cmd[4].split(" "))[1]);rn intent.setClass(MainActivity.this,ListActivity.class);rn (MainActivity.this).startActivity(intent);rn rn catch (IOException e) rn rn // TODO Auto-generated catch blockrn e.printStackTrace();rn rn rn rn private String[] parse(String rece)rn rn String[] elem=null;rn elem=rece.split("/");rn return elem;rn rn rn @Overridern public boolean onCreateOptionsMenu(Menu menu)rn rn // Inflate the menu; this adds items to the action bar if it is present.rn getMenuInflater().inflate(R.menu.main, menu);rn return true;rn rn @Overridern protected void onDestroy()rn rn // TODO Auto-generated method stubrn super.onDestroy();rn if(socket!=null)rn rn tryrn rn socket.close();rn rn catch (IOException e)rn rn // TODO Auto-generated catch blockrn e.printStackTrace();rn rn rn if(br!=null)rn rn try rn rn br.close();rn rn catch (IOException e) rn rn // TODO Auto-generated catch blockrn e.printStackTrace();rn rn rn if(bw!=null)rn rn try rn rn bw.close();rn rn catch (IOException e) rn rn // TODO Auto-generated catch blockrn e.printStackTrace();rn rn rn// it.destroy();rn// receThread.destroy();rn rn rn rn

大神帮小弟看看问题所在!

01-01

程序能够运行,但是打开附件的秒表点击按钮没有反应,单独一个秒表程序可以。请大神看看问题出在哪里,帮忙修改一下,感激不尽[code=java]import java.awt.*;rnrnimport javax.swing.*;rnrnimport java.awt.event.*;rnrnpublic class NotePad extends JFrame rn JTextArea jta;rnrn class newl implements ActionListener rn public void actionPerformed(ActionEvent e) rn jta.setText("");rn rn rnrn class openl implements ActionListener rn public void actionPerformed(ActionEvent e) rn JFileChooser jf = new JFileChooser();rn jf.showOpenDialog(NotePad.this);rnrn rnrn rnrn // 保存文件的监听rn class savel implements ActionListener rn public void actionPerformed(ActionEvent e) rn JFileChooser jf = new JFileChooser();rn jf.showSaveDialog(NotePad.this);rnrn rn rnrn // 退出记事本的监听rn class exitl implements ActionListener rn public void actionPerformed(ActionEvent e) rn System.exit(0);// 退出rn rn rnrn class timerl implements ActionListener rn public void actionPerformed(ActionEvent e) rn new TestTimer() ;// 秒表rn rn rnrn class tipl implements ActionListener rn public void actionPerformed(ActionEvent e) rn JOptionPane.showMessageDialog(null, "程序 信息");rn rn rn // 构造函数rn public NotePad() rn jta = new JTextArea("", 24, 40);rn JScrollPane jsp = new JScrollPane(jta);rn JMenuBar jmb = new JMenuBar();rn JMenu mFile = new JMenu("文件");rn JMenu mStuff = new JMenu("附件");rn JMenu mHelp= new JMenu("帮助");rnrn JMenuItem mNew = new JMenuItem("新建");rn mNew.addActionListener(new newl());rn mFile.add(mNew);rnrn JMenuItem mOpen = new JMenuItem("打开");rn mOpen.addActionListener(new openl());rn mFile.add(mOpen);rnrn JMenuItem mSave = new JMenuItem("保存");rn mSave.addActionListener(new savel());rn mFile.add(mSave);rnrn mFile.addSeparator(); // 添加分割线rn rn JMenuItem mExit=new JMenuItem("退出");rn mExit.addActionListener(new exitl());rn mFile.add(mExit);rn //rn JMenuItem mTime=new JMenuItem("秒表");rn mTime.addActionListener(new timerl());rn mStuff.add(mTime);rn rn JMenuItem mTi=new JMenuItem("关于");rn mTi.addActionListener(new tipl());rn mHelp.add(mTi);rnrn rn jmb.add(mFile);rn jmb.add(mStuff);rn jmb.add(mHelp);rnrn setJMenuBar(jmb);rnrn setTitle("课程设计 ");rn getContentPane().add(jsp);rn setSize(634, 500);rn setVisible(true);rn rnrn// 主函数,程序入口点rn public static void main(String s[]) rn new NotePad();rn rnrnrnrn/*.........................................................*/rnclass TestTimer extends JFrame implements ActionListener, Runnable rn private static TestTimer obj;rn private JButton btnStart;rn private JButton btnPause;rn private JButton btnResume;rn private JButton btnStop;rn private JLabel lblTime;rn private static Thread th;rn private long count;rnrn public TestTimer() rn super("秒表");rn btnStart = new JButton("开始");rn btnPause = new JButton("暂停");rn btnResume = new JButton("继续");rn btnStop = new JButton("停止");rn lblTime = new JLabel("00:00:00.000");rn this.setLayout(new FlowLayout());rn this.add(btnStart);rn this.add(btnPause);rn this.add(btnResume);rn this.add(btnStop);rn this.add(lblTime);rn btnStart.addActionListener(this);rn btnPause.addActionListener(this);rn btnResume.addActionListener(this);rn btnStop.addActionListener(this);rn this.setSize(167, 144);rn this.setResizable(false);rn this.setVisible(true);rn rnrn public static void main(String[] args) rn obj = new TestTimer();rn rnrnrn public void actionPerformed(ActionEvent e) rn JButton btn = (JButton) e.getSource();rn if (btn.getText().equals("开始")) rn th = new Thread(obj);rn count = 0;rn th.start();rn else if (btn.getText().equals("暂停")) rn th.suspend();rn else if (btn.getText().equals("继续")) rn th.resume();rn else if (btn.getText().equals("停止")) rn th.stop();rn rn rnrn public void run() rn while (true) rn int ms, seconds, minutes, hours;rn String msg = "";rn hours = (int) (count / 3600000);rn minutes = (int) ((count - hours * 3600000) / 60000);rn seconds = (int) ((count - hours * 3600000 - minutes * 60000) / 1000);rn ms = (int) (count % 1000);rn if (hours < 10) rn msg += "0" + hours + ":";rn else rn msg += hours + ":";rn rn if (minutes < 10) rn msg += "0" + minutes + ":";rn else rn msg += minutes + ":";rn rn if (seconds < 10) rn msg += "0" + seconds + ":";rn else rn msg += seconds + ":";rn rn if (ms < 10) rn msg += "00" + ms;rn else if (ms < 100) rn msg += "0" + ms;rn else rn msg += ms;rn rn lblTime.setText(msg);rn count++;rn try rn Thread.sleep(1);rn catch (InterruptedException e) rn e.printStackTrace();rn rn rn rnrn[/code]

没有更多推荐了,返回首页

私密
私密原因:
请选择设置私密原因
  • 广告
  • 抄袭
  • 版权
  • 政治
  • 色情
  • 无意义
  • 其他
其他原因:
120
出错啦
系统繁忙,请稍后再试

关闭