
微信计算器使用的步骤有3步,我们可以直接在微信的小程序之中使用计算器。以下是具体 *** 作步骤:
1、打开微信然后选择右上方搜索符号。
2、输入计算器然后选择小程序进入
3、选择好功能然后直接使用即可行卜凯
备注:微信没有自带的计算器功能,他所提供的计算器功能是其他人开发出来的小程序。
有的输入法也有计算器,还有其它的你可以去找一下。
拓展计算器是现代人发明的可以进行数字弊让运算的电子机器。
现代的电子计算器能进行数学运算的手持电子机器,拥有集成电路芯片,但结构比电脑简单得多,可以说是第档唤一代的电子计算机(电脑),且功能也较弱,但较为方便与廉价,可广泛运用于商业交易中,是必备的办公用品之一。除显示计算结果外,还常有溢出指示、错误指示等。计算器电源采用交流转换器或电池,电池可用交流转换器或太阳能转换器再充电。为节省电能,计算器都采用CMOS工艺制作的大规模集成电路。
下面两个可以么,是我做实验答辩时用到的!import java.awt.*//AWT核心包
import java.awt.event.*//提供事件类和监听器
public class Counter extends Frame implements ActionListener
{
TextField t=new TextField("")//文本框
Panel p1=new Panel()//new一个panel,用于存放数字键和符号键。
Panel p2=new Panel()//new一个panel,用于存放开方、平方、和清除键。
Button[] b=new Button[10]//实例化Button对象
Button bAdd=new Button("加")
Button bSub=new Button("减")
Button bMul=new Button("乘以")
Button bPoint=new Button(".")
Button bDiv=new Button("除以")
Button bEqual=new Button("等於")
Button bSqrt=new Button("开方")
Button bPow=new Button("平方")
Button bNull=new Button("清除")
String str1=""//str1和str2存放两个输入的数
String str2=""
String operator=null //存放加减乘除以及开平方的符号
boolean first=true //检验输入的是否为第一个数
int countOper=0 //累计输入符号的个数,连加连减等 *** 作中会用到
double result=0.0 //暂存结果
double num1=0.0,num2=0.0 //两个输入的数做运算时转化为double存放
boolean error=false //检验除数是否州型吵为0
//构造方租源法
public Counter()
{
Frame s=new Frame("计算器")//创建Frame
for(int i=0i<10i++)//利用for循环将数字键添加进p1中
{
b[i]=new Button(String.valueOf(i))
p1.add(b[i])
b[i].setActionCommand("number")
b[i].setForeground(new Color(150,20,20))
b[i].addActionListener(this)//调用addActionListener()方法注册事件监听器
}
p1.add(bPoint)
bPoint.setActionCommand("number")
p1.add(bAdd)//数字键,符号键放置在panel的p1中
p1.add(bSub)
p1.add(bMul)
p1.add(bDiv)
p1.add(bEqual)
p2.add(bSqrt)//开方键,平方键,清除键放置在panel的p2中
p2.add(bPow)
p2.add(bNull)
bAdd.setActionCommand("oper")
bSub.setActionCommand("oper")
bMul.setActionCommand("oper")
bDiv.setActionCommand("oper")
bAdd.setForeground(Color.red)//为组键设计颜册侍色
bSub.setForeground(Color.red)
bMul.setForeground(Color.red)
bDiv.setForeground(Color.red)
bPoint.setForeground(Color.black)
bEqual.setForeground(Color.red)
bSqrt.setForeground(Color.blue)
bPow.setForeground(Color.blue)
bNull.setForeground(Color.blue)
bAdd.addActionListener(this)//调用addActionListener()方法注册事件监听器
bSub.addActionListener(this)
bMul.addActionListener(this)
bDiv.addActionListener(this)
bPoint.addActionListener(this)
bEqual.addActionListener(this)
bSqrt.addActionListener(this)
bPow.addActionListener(this)
bNull.addActionListener(this)
p1.setLayout(new GridLayout(4,4,5,5))//网格布局管理器,把容器根据行数和列数分成同样大小的单元,
//每个单元可容纳一个组件,并且此组件会填满网格单元,不能控
//制其占据网格的大小。4、4为网格的行、列数。5、5为组建之间的
//间距
p2.setLayout(new FlowLayout())//用FlowLayout布局管理器将组建默认剧中排放,默认间隙为5个像素
add(t,"North") //frame的north放置输入框,panel放置在center和south
add(p1,"Center")//将p1添加到Center中
add(p2,"South")//将p2添加到South中
setLocation(400,200)//设计按钮尺寸
setSize(200,200)//设计窗口尺寸
setBackground(new Color(20,200,10))//设置Frame的背景,默认为白色
setVisible(true)//设置Frame设置为可见
addWindowListener(new WindowAdapter(){ //关闭窗口功能
public void windowClosing(WindowEvent e)
{
System.exit(0)
}
})
}
//实现接口ActionListener
public void actionPerformed(ActionEvent e)
{
Button temp=(Button)e.getSource()
if(e.getActionCommand().equals("number"))
{
if(first)
{
str1=str1+temp.getLabel()
t.setText(str1)//将输入的str1显示在文本框中
}
else
{
str2=str2+temp.getLabel()
t.setText(str2)//将输入的str2显示在文本框中
}
}
else if(e.getActionCommand().equals("oper"))
{
if(str1=="")//如果还没有输入数就点击运算符执行if
{
countOper=0//若此,则将计数清零
first=true
}
else
{
countOper++//计算输入符号的个数
if(countOper>1)//若输入的符号个数多余一个,则可以进行计算
{
getResult()
}
operator=temp.getLabel()//存放加减乘除以及开方、平方的符号
first=false
}
}
else if(e.getActionCommand().equals("开方"))
{
double d=Math.sqrt(Double.parseDouble(str1))
str1=String.valueOf(d)//将计算出来的结果再次传给str1,为连计算准备
t.setText(String.valueOf(d))//将计算出来的结果传至文本框中
first=false//置为false,即已输入第一个数
}
else if(e.getActionCommand().equals("平方"))
{
double f=Math.pow(Double.parseDouble(str1),2)
str1=String.valueOf(f)
t.setText(String.valueOf(f))
first=false
}
else if(e.getActionCommand().equals("清除"))
{
str1=""//清空
str2=""
t.setText("")//将文本框清空
countOper=0//将按键计数器清零
first=true
error=false
}
else if(e.getActionCommand().equals("等於"))
{
if((str1=="")||(str2=="")) //两个数没有输全就点击等号,执行if
{
countOper=0//将按键计数器清零
first=true
}
else
{
getResult()
countOper=0
}
}
}
//运算结果的方法
public void getResult()
{
num1=Double.parseDouble(str1)
num2=Double.parseDouble(str2)
if(operator.equals("加"))
{
result=num1+num2
}
else if(operator.equals("减"))
{
result=num1-num2
}
else if(operator.equals("乘以"))
{
result=num1*num2
}
else if(operator.equals("除以"))
{
if(num2==0.0)//除数为0的处理方法
{
error=true
}
else
{
result=num1/num2
}
}
if(error)
{
t.setText("error")
}
else
{
t.setText(String.valueOf(result))
str1=String.valueOf(result) //运算后把结果放入str1中,str2清空,为连加连减等 *** 作做准备
str2=""
}
}
//主方法
public static void main(String[] args)
{
new Counter()//创建一个对象"计算器"
}
}
import java.awt.*
import java.awt.event.*
import javax.swing.*
class CalculatorPanel extends JPanel
implements ActionListener
{ public CalculatorPanel()
{ setLayout(new BorderLayout())
display = new JTextField("0")
display.setEditable(false)
add(display, "North")
JPanel p = new JPanel()
p.setLayout(new GridLayout(4, 4))
String buttons = "789/456*123-0.=+"
for (int i = 0 i < buttons.length() i++)
addButton(p, buttons.substring(i, i + 1))
add(p, "Center")
}
private void addButton(Container c, String s)
{ JButton b = new JButton(s)
c.add(b)
b.addActionListener(this)
}
public void actionPerformed(ActionEvent evt)
{ String s = evt.getActionCommand()
if ('0' <= s.charAt(0) && s.charAt(0) <= '9'
|| s.equals("."))
{ if (start) display.setText(s)
else display.setText(display.getText() + s)
start = false
}
else
{ if (start)
{ if (s.equals("-"))
else op = s
}
else
{ calculate(Double.parseDouble(display.getText()))
op = s
start = true
}
}
}
public void calculate(double n)
{ if (op.equals("+")) arg += n
else if (op.equals("-")) arg -= n
else if (op.equals("*")) arg *= n
else if (op.equals("/")) arg /= n
else if (op.equals("=")) arg = n
display.setText("" + arg)
}
private JTextField display
private double arg = 0
private String op = "="
private boolean start = true
}
public class CalculatorApplet extends JApplet
{ public void init()
{ Container contentPane = getContentPane()
contentPane.add(new CalculatorPanel())
}
}
#include<stdio.h>烂尘#include<stdlib.h>
#include<time.h>
void main()
{ int a,b,i,c,d,p=1,m=0,n=0
a=rand()%100b=rand()%100
for(i=0i<10i++)
printf("*")
printf("\n* 1.加法 *\n")
printf("\n* 2.减法 *\n")
printf("启毁\n* 3.乘法 *\n")
printf("\n* 4.除法 *\n")
for(i=0i<10i++)
printf("*")
while(p)
{ printf("\n请选择 *** 作n(1-6):")
scanf("%d",&c)
c=c%6
printf("\n请输入答案:\n")
switch(c)
{ case 0:exit(1)
case 1:c='+'printf("%d+%d=\n",a,b)scanf("%d",&d)
while(m<3&&p)
{if(d==a+b)<br/>{printf("good,你的答案是正确的")<br/> n++p=0}
else
printf("\n对不起,你的答案是错误的\n请输入正确答案:\n%d+%d=\n",a,b)
m++scanf("%d",&d) } p=1
break
case 2:c='-'printf("%d-%d=\n",a,b)
scanf("%d",&d)
while(m<3&&p)
{if(d==a-b)<br/>{printf("good,你的答案是正确的")<br/> n++p=0}
else
printf("\n对不起,你的答案是错误的\n请输入正确答案:\n%d-%d=\n",a,b)
m++scanf("%d",&d)} p=1
break
case 3:c='*'printf("%d*%d=\n",a,b)
scanf("%d",&d)
while(m<3&&p)
{if(d==a*b)<br/>{printf("good,你的答案是正确的")<悄历备br/> n++p=0}
else
printf("\n对不起,你的答案是错误的\n请输入正确答案:\n%d*%d=\n",a,b)
m++scanf("%d",&d)} p=1
break
case 4:c='/'printf("%f/%f=\n",(float)a,(float)b)
scanf("%d",&d)
while(m<3&&p)
{if(d==(float)a/(float)b)<br/>{printf("good,你的答案是正确的")<br/> n++p=0}
else
printf("\n对不起,你的答案是错误的\n请输入正确答案:\n%d-%d=\n",a,b)
m++scanf("%d",&d)} p=1break
case 5:printf("\n你一共做对了%d,错了%d\n",n,m)break
}
}
}
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)