求Java源代码:用Java实现输出:输入一个整数,输出此数为几位数 。public class Test{
public static void main(String[] args) {
int i=12345;//假设
String s="" i;
System.out.println(s.length() "位数");
}
}
java中如何获得某一整数的某一个字节的数据,例如8,他的二进制原码00000001 0000000,getAnyBinaryString(int num,int start,int end){ //i是你要取的某个字节,按数值实际存储大小来赋值能取的范围0~64表示8位到64位的可取字节即byte到long,如数值num实际只用了一字节存那么start=0,end=8也就是说你只能取到num的第1个字节,其他位都是1取出来无用不是真值,环境默认数值为int32位0~8|8~16|16~24|24~32(表示0~3的某个字节)以实际数值存储所占字节大小为准,你可事先算下数值是几位表示;
return (num=0?Integer.toBinaryString(num):Integer.toBinaryString(~num 1)).substring(start, end);
}
我想要一个JAVA边的计算器的原码并有代码说明文档import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.math.*;
public class HomeWork61 extends JFrame
{
JTextField memory=new JTextField();
JTextField number=new JTextField();
String before=new String();//存储没输入完的数
String first=new String();//第一个数
String second=new String();//第二个数
String symbol=new String();//存储运算符号
String remember=new String();
int point;//点过小数点否
class buttonlistener implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
String s=e.getActionCommand();
if(s=="1"||s=="2"||s=="3"||s=="4"||s=="5"||s=="6"||s=="7"||s=="8"||s=="9"||s=="0"||s==".")
{
if(s!=".")
before=before s;
else
if(point==0)
{
before=before s;
point=1;
}
number.setText(before);
}
else
if(s==" "||s=="-"||s=="*"||s=="/")
{
if(first=="")
first=before;
else
{
second=before;
String result=new String();
double finalnumber=0;
if(symbol==" ")
finalnumber=Double.parseDouble(first) Double.parseDouble(second);
if(symbol=="-")
finalnumber=Double.parseDouble(first)-Double.parseDouble(second);
if(symbol=="*")
finalnumber=Double.parseDouble(first)*Double.parseDouble(second);
if(symbol=="/")
finalnumber=Double.parseDouble(first)/Double.parseDouble(second);
if(symbol=="=")
finalnumber=Double.parseDouble(first);
result=result.valueOf(finalnumber);
number.setText(result);
first=result;
point=0;
}
symbol=s;
before="";
point=0;
}
else
if(s=="=")
{
second=before;
before="";
String result=new String();
double finalnumber=0;
if(symbol==" ")
finalnumber=Double.parseDouble(first) Double.parseDouble(second);
if(symbol=="-")
finalnumber=Double.parseDouble(first)-Double.parseDouble(second);
if(symbol=="*")
finalnumber=Double.parseDouble(first)*Double.parseDouble(second);
if(symbol=="/")
finalnumber=Double.parseDouble(first)/Double.parseDouble(second);
result=result.valueOf(finalnumber);
number.setText(result);
symbol="=";
first=result;
point=0;
}
if(s=="sin"||s=="cos"||s=="tan")//三角函数
{
if(first=="")
first=before;
before="";
String result=new String();
double finalnumber=0;
if(s=="sin")
finalnumber=Math.sin(Double.parseDouble(first));
if(s=="cos")
finalnumber=Math.cos(Double.parseDouble(first));
if(s=="tan")
finalnumber=Math.tan(Double.parseDouble(first));
result=result.valueOf(finalnumber);
number.setText(result);
first=result;
symbol="=";
point=0;
}
if(s==" /-")//正负转换
{
if(first=="")
{
first=before;
before="";
String result=new String();
double finalnumber=Double.parseDouble(first);
finalnumber=-finalnumber;
result=result.valueOf(finalnumber);
number.setText(result);
first=result;
symbol="=";
point=0;
}
else
{
String result=new String();
double finalnumber=Double.parseDouble(before);
finalnumber=-finalnumber;
result=result.valueOf(finalnumber);
number.setText(result);
before=result;
point=0;
}
}
if(s=="M ")
{
if(before!="")
{
if(remember=="")
remember=before;
else
{
double finalnumber=Double.parseDouble(remember) Double.parseDouble(before);
remember=remember.valueOf(finalnumber);
}
before="";
point=0;
memory.setText("M");
}
}
if(s=="MR")
{
if(remember!="")
number.setText(remember);
else
number.setText("0.");
}
if(s=="MC")
{
memory.setText("");
remember="";
}
if(s=="MS")
{
if(before!="")
{
remember=before;
before="";
point=0;
memory.setText("M");
}
}
if(s=="C")//清除屏幕
{
before="";
first="";
second="";
symbol="";
point=0;
number.setText("0.");
}
}
}
public static void main(String[] args)
{
HomeWork61 myhomework=new HomeWork61("calculator");//生成对象
myhomework.setSize(400,200);//设置大小
myhomework.setVisible(true);//设置成可见
}
public HomeWork61(String title)
{
super(title);//设置标题
Container cp = getContentPane();
JPanel button=new JPanel();
JPanel result=new JPanel();
remember="";
before="";
first="";
second="";
symbol="";
point=0;
JButton c=new JButton();
button.setLayout(new GridLayout(4,6));
result.setLayout(new GridLayout(1,3));
JButton[] btn=new JButton[24];
btn[0]=new JButton("sin");
btn[1]=new JButton("MC");
btn[2]=new JButton("0");
btn[3]=new JButton("1");
btn[4]=new JButton("2");
btn[5]=new JButton(" ");
btn[6]=new JButton("cos");
btn[7]=new JButton("MR");
btn[8]=new JButton("3");
btn[9]=new JButton("4");
btn[10]=new JButton("5");
btn[11]=new JButton("-");
btn[12]=new JButton("tan");
btn[13]=new JButton("MS");
btn[14]=new JButton("6");
btn[15]=new JButton("7");
btn[16]=new JButton("8");
btn[17]=new JButton("*");
btn[18]=new JButton(" /-");
btn[19]=new JButton("M ");
btn[20]=new JButton("9");
btn[21]=new JButton(".");
btn[22]=new JButton("=");
btn[23]=new JButton("/");
c=new JButton("C");
for(int i=0;i24;i)
{
btn[i].addActionListener(new buttonlistener());
button.add(btn[i]);
}
c.addActionListener(new buttonlistener());
result.add(BorderLayout.EAST,memory);
result.add(BorderLayout.CENTER,c);
result.add(BorderLayout.WEST,number);
cp.add(BorderLayout.NORTH,result);
cp.add(BorderLayout.SOUTH,button);
number.setText("0.");
}
}
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.math.*;
public class HomeWork61 extends JFrame
{
JTextField memory=new JTextField();
JTextField number=new JTextField();
String before=new String();//存储没输入完的数
String first=new String();//第一个数
String second=new String();//第二个数
String symbol=new String();//存储运算符号
String remember=new String();
int point;//点过小数点否
class buttonlistener implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
String s=e.getActionCommand();
if(s=="1"||s=="2"||s=="3"||s=="4"||s=="5"||s=="6"||s=="7"||s=="8"||s=="9"||s=="0"||s==".")
{
if(s!=".")
before=before s;
else
if(point==0)
{
before=before s;
point=1;
}
number.setText(before);
}
else
if(s==" "||s=="-"||s=="*"||s=="/")
{
if(first=="")
first=before;
else
{
second=before;
String result=new String();
double finalnumber=0;
if(symbol==" ")
finalnumber=Double.parseDouble(first) Double.parseDouble(second);
if(symbol=="-")
finalnumber=Double.parseDouble(first)-Double.parseDouble(second);
if(symbol=="*")
finalnumber=Double.parseDouble(first)*Double.parseDouble(second);
if(symbol=="/")
finalnumber=Double.parseDouble(first)/Double.parseDouble(second);
if(symbol=="=")
finalnumber=Double.parseDouble(first);
result=result.valueOf(finalnumber);
number.setText(result);
first=result;
point=0;
}
symbol=s;
before="";
point=0;
}
else
if(s=="=")
{
second=before;
before="";
String result=new String();
double finalnumber=0;
if(symbol==" ")
finalnumber=Double.parseDouble(first) Double.parseDouble(second);
if(symbol=="-")
finalnumber=Double.parseDouble(first)-Double.parseDouble(second);
if(symbol=="*")
finalnumber=Double.parseDouble(first)*Double.parseDouble(second);
if(symbol=="/")
finalnumber=Double.parseDouble(first)/Double.parseDouble(second);
result=result.valueOf(finalnumber);
number.setText(result);
symbol="=";
first=result;
point=0;
}
if(s=="sin"||s=="cos"||s=="tan")//三角函数
{
if(first=="")
first=before;
before="";
String result=new String();
double finalnumber=0;
if(s=="sin")
finalnumber=Math.sin(Double.parseDouble(first));
if(s=="cos")
finalnumber=Math.cos(Double.parseDouble(first));
if(s=="tan")
finalnumber=Math.tan(Double.parseDouble(first));
result=result.valueOf(finalnumber);
number.setText(result);
first=result;
symbol="=";
point=0;
}
if(s==" /-")//正负转换
{
if(first=="")
{
first=before;
before="";
String result=new String();
double finalnumber=Double.parseDouble(first);
finalnumber=-finalnumber;
result=result.valueOf(finalnumber);
number.setText(result);
first=result;
symbol="=";
point=0;
}
else
{
String result=new String();
double finalnumber=Double.parseDouble(before);
finalnumber=-finalnumber;
result=result.valueOf(finalnumber);
number.setText(result);
before=result;
point=0;
}
}
if(s=="M ")
{
if(before!="")
{
if(remember=="")
remember=before;
else
{
double finalnumber=Double.parseDouble(remember) Double.parseDouble(before);
remember=remember.valueOf(finalnumber);
}
before="";
point=0;
memory.setText("M");
}
}
if(s=="MR")
{
if(remember!="")
number.setText(remember);
else
number.setText("0.");
}
if(s=="MC")
{
memory.setText("");
remember="";
}
if(s=="MS")
{
if(before!="")
{
remember=before;
before="";
point=0;
memory.setText("M");
}
}
if(s=="C")//清除屏幕
{
before="";
first="";
second="";
symbol="";
point=0;
number.setText("0.");
}
}
}
public static void main(String[] args)
{
HomeWork61 myhomework=new HomeWork61("calculator");//生成对象
myhomework.setSize(400,200);//设置大小
myhomework.setVisible(true);//设置成可见
}
public HomeWork61(String title)
{
super(title);//设置标题
Container cp = getContentPane();
JPanel button=new JPanel();
JPanel result=new JPanel();
remember="";
before="";
first="";
second="";
symbol="";
point=0;
JButton c=new JButton();
button.setLayout(new GridLayout(4,6));
result.setLayout(new GridLayout(1,3));
JButton[] btn=new JButton[24];
btn[0]=new JButton("sin");
btn[1]=new JButton("MC");
btn[2]=new JButton("0");
btn[3]=new JButton("1");
btn[4]=new JButton("2");
btn[5]=new JButton(" ");
btn[6]=new JButton("cos");
btn[7]=new JButton("MR");
btn[8]=new JButton("3");
btn[9]=new JButton("4");
btn[10]=new JButton("5");
btn[11]=new JButton("-");
btn[12]=new JButton("tan");
btn[13]=new JButton("MS");
btn[14]=new JButton("6");
btn[15]=new JButton("7");
btn[16]=new JButton("8");
btn[17]=new JButton("*");
btn[18]=new JButton(" /-");
btn[19]=new JButton("M ");
btn[20]=new JButton("9");
btn[21]=new JButton(".");
btn[22]=new JButton("=");
btn[23]=new JButton("/");
c=new JButton("C");
for(int i=0;i24;i)
Java:Integer.bitCount()原码求解只是一种算法,就像贴吧里经常有,随机选个数 , 然后把这个数加上多少减去多少还有一些特殊步骤,然后那个楼主就说你得到的一定是某个数 。用数学的方法证明一下就可以了
【java求整数原码代码 java求整数原码代码是多少】java求整数原码代码的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于java求整数原码代码是多少、java求整数原码代码的信息别忘了在本站进行查找喔 。
推荐阅读
- 永恒之塔斗鱼直播奖励兑换,永恒之塔怀旧直播
- html5浪漫,html浪漫唯美代码
- 漫画恋爱游戏男主,漫画版恋爱游戏
- 小红书如何制作推广视频,小红书的推广视频
- php接收处理xml数据 php接收post数据并查询数据库
- flutterscaffold的使用,flutterng
- sap冻结采购订单,sap 冻结库存
- 微信剪视频小程序制作过程,微信剪辑视频小程序
- c语言两个库函数 c语言里的库函数