RELATEED CONSULTING
相关咨询
选择下列产品马上在线沟通
服务时间:8:30-17:00
你可能遇到了下面的问题
关闭右侧工具栏

新闻中心

这里有您想知道的互联网营销解决方案
java求整数原码代码 整数原码的计算方法

我想要一个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中如何获得某一整数的某一个字节的数据,例如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求整数原码代码 整数原码的计算方法
网页链接:http://lswzjz.com/article/hppigp.html