资讯

精准传达 • 有效沟通

从品牌网站建设到网络营销策划,从策略到执行的一站式服务

简单的java计算机代码,java编写计算机

求JAVA编写的 简易计算器程序,附上注释

1、首先准备好软件即eclipse和java,下载安装完成后打开eclipse。

创新互联公司专注于苏州企业网站建设,成都响应式网站建设,成都商城网站开发。苏州网站建设公司,为苏州等地区提供建站服务。全流程按需定制网站,专业设计,全程项目跟踪,创新互联公司专业和态度为您提供的服务

2、点击左上角的file 新建一个project。

3、给project取一个名字,其他的选项都是默认然后点击finish。

4、接下来是新建一个class。

5、在给class取名字的时候注意用英文名的首字母要大写。完成后点击finish。

6、这就是开始写代码的工作台,将代码写在绿字下。

7、这就是第一个hello world程序。

急求java简易计算器代码

试试下面的代码 绝对没有错误。

package main;

import java.awt.Button;

import java.awt.Color;

import java.awt.GridLayout;

import java.awt.Panel;

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

import java.math.BigDecimal;

import javax.swing.JFrame;

import javax.swing.JTextField;

public class app7 extends JFrame implements ActionListener {

static Panel pan = new Panel();

static JTextField textField = new JTextField("0");

static Button b0, b1, b2, b3, b4, b5, b6, b7, b8, b9, bp, ba, bs, bm, bd,

be, bc, bt, bf, bh;

private StringBuffer temp = new StringBuffer("");

private String optValue = "0";

private String optType="";

private boolean isChoiseOptType=true;

public void init() {

b0 = new Button("0");

b0.addActionListener(this);

b1 = new Button("1");

b1.addActionListener(this);

b2 = new Button("2");

b2.addActionListener(this);

b3 = new Button("3");

b3.addActionListener(this);

b4 = new Button("4");

b4.addActionListener(this);

b5 = new Button("5");

b5.addActionListener(this);

b6 = new Button("6");

b6.addActionListener(this);

b7 = new Button("7");

b7.addActionListener(this);

b8 = new Button("8");

b8.addActionListener(this);

b9 = new Button("9");

b9.addActionListener(this);

bp = new Button(".");

bp.addActionListener(this);

ba = new Button("+");

ba.addActionListener(this);

bs = new Button("-");

bs.addActionListener(this);

bm = new Button("*");

bm.addActionListener(this);

bd = new Button("/");

bd.addActionListener(this);

be = new Button("=");

be.addActionListener(this);

bc = new Button("c");

bc.addActionListener(this);

bt = new Button("退格");

bt.addActionListener(this);

bf = new Button("1/x");

bf.addActionListener(this);

bh = new Button("+/-");

bh.addActionListener(this);

this.setTitle("计算机");

this.setLayout(null);

this.setSize(260, 300);

this.setResizable(false);

GridLayout grid = new GridLayout(4, 5);

pan.setLayout(grid);

pan.setBounds(20, 60, 150, 120);

textField.setBounds(20, 35, 150, 20);

textField.setBackground(Color.cyan);

textField.setHorizontalAlignment(textField.RIGHT);

textField.setEditable(false);

pan.add(b1);

pan.add(b2);

pan.add(b3);

pan.add(ba);

pan.add(bc);

pan.add(b4);

pan.add(b5);

pan.add(b6);

pan.add(bs);

pan.add(bt);

pan.add(b7);

pan.add(b8);

pan.add(b9);

pan.add(bm);

pan.add(bf);

pan.add(b0);

pan.add(bh);

pan.add(bp);

pan.add(bd);

pan.add(be);

this.add(textField);

this.add(pan);

}

public static void main(String[] args) {

app7 frm = new app7();

frm.init();

frm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

frm.setVisible(true);

}

@SuppressWarnings("static-access")

@Override

public void actionPerformed(ActionEvent e) {

String value="0";

if (e.getSource().equals(b0)) {

this.temp.append(b0.getLabel());

this.textField.setText(this.temp.toString());

isChoiseOptType=false;

} else if (e.getSource().equals(b1)) {

this.temp.append(b1.getLabel());

this.textField.setText(this.temp.toString());

isChoiseOptType=false;

} else if (e.getSource().equals(b2)) {

this.temp.append(b2.getLabel());

this.textField.setText(this.temp.toString());

isChoiseOptType=false;

} else if (e.getSource().equals(b3)) {

this.temp.append(b3.getLabel());

this.textField.setText(this.temp.toString());

isChoiseOptType=false;

} else if (e.getSource().equals(b4)) {

this.temp.append(b4.getLabel());

this.textField.setText(this.temp.toString());

isChoiseOptType=false;

} else if (e.getSource().equals(b5)) {

this.temp.append(b5.getLabel());

this.textField.setText(this.temp.toString());

isChoiseOptType=false;

} else if (e.getSource().equals(b6)) {

this.temp.append(b6.getLabel());

this.textField.setText(this.temp.toString());

isChoiseOptType=false;

} else if (e.getSource().equals(b7)) {

this.temp.append(b7.getLabel());

this.textField.setText(this.temp.toString());

isChoiseOptType=false;

} else if (e.getSource().equals(b8)) {

this.temp.append(b8.getLabel());

this.textField.setText(this.temp.toString());

isChoiseOptType=false;

} else if (e.getSource().equals(b9)) {

this.temp.append(b9.getLabel());

this.textField.setText(this.temp.toString());

isChoiseOptType=false;

} else if (e.getSource().equals(bp)) {

if(this.temp.length()=0)

this.temp.append("0");

this.temp.append(bp.getLabel());

this.textField.setText(this.temp.toString());

isChoiseOptType=false;

} else if (e.getSource().equals(ba)) {

if(!isChoiseOptType){

value=this.textField.getText();

if(value.lastIndexOf(".")==value.length()-1){

value=value.substring(0,value.length()-1);

}

this.optValue=value;

this.temp=new StringBuffer("");

}

this.optType=ba.getLabel();

isChoiseOptType=true;

} else if (e.getSource().equals(bs)) {

if(!isChoiseOptType){

value=this.textField.getText();

if(value.lastIndexOf(".")==value.length()-1){

value=value.substring(0,value.length()-1);

}

this.optValue=value;

this.temp=new StringBuffer("");

}

this.optType=bs.getLabel();

isChoiseOptType=true;

} else if (e.getSource().equals(bm)) {

if(!isChoiseOptType){

value=this.textField.getText();

if(value.lastIndexOf(".")==value.length()-1){

value=value.substring(0,value.length()-1);

}

this.optValue=value;

this.temp=new StringBuffer("");

}

this.optType=bm.getLabel();

isChoiseOptType=true;

} else if (e.getSource().equals(bd)) {

if(!isChoiseOptType){

value=this.textField.getText();

if(value.lastIndexOf(".")==value.length()-1){

value=value.substring(0,value.length()-1);

}

this.optValue=value;

this.temp=new StringBuffer("");

}

this.optType=bd.getLabel();

isChoiseOptType=true;

}else if (e.getSource().equals(be)) {

if(!this.optType.equals("")){

BigDecimal opt1=new BigDecimal(this.optValue);

value=this.textField.getText();

if(value.lastIndexOf(".")==value.length()-1){

value=value.substring(0,value.length()-1);

}

BigDecimal opt2=new BigDecimal(value);

BigDecimal result=new BigDecimal(0);

if(this.optType.equals("+")){

result=opt1.add(opt2);

}else if(this.optType.equals("-")){

result=opt1.subtract(opt2);

}else if(this.optType.equals("*")){

result=opt1.multiply(opt2);

}else if(this.optType.equals("/")){

result=opt1.divide(opt2);

}else if(this.optType.equals("%")){

result=opt1.remainder(opt2);

}

this.textField.setText(result.toString());

this.temp=new StringBuffer("");

isChoiseOptType=false;

this.optValue="0";

}

} else if (e.getSource().equals(bc)) {

this.temp=new StringBuffer();

this.textField.setText("0");

} else if (e.getSource().equals(bt)) {

value=this.textField.getText();

value=value.substring(0,value.length()-1);

if(value.indexOf("-")=0 value.length()=1){

value="0";

this.temp=new StringBuffer("");

}else{

this.temp=new StringBuffer(value);

}

this.textField.setText(value);

}else if (e.getSource().equals(bh)) {

value=this.textField.getText();

if(value.indexOf("-")==0){

value=value.substring(1,value.length());

}else{

value="-"+value;

}

this.temp=new StringBuffer(value);

this.textField.setText(value);

} else if (e.getSource().equals(bf)) {

this.optValue=this.textField.getText();

if(value.lastIndexOf(".")==value.length()-1){

this.optValue=this.optValue.substring(0,this.optValue.length()-1);

}

Integer opt1=new Integer(this.optValue);

if(!opt1.toString().equals("0")){

this.textField.setText(1.0/opt1.intValue()+"");

System.out.println(1/opt1.intValue()+"");

}else{

this.textField.setText("0");

}

this.temp=new StringBuffer("");

this.optType="";

this.optValue="0";

}

}

}

记住类名是app7.java 包名是main. 如果有不对的地方 到时候在找我 我在线。

我需要一段最简单的java代码程序

public class HelloWorld{

public static void main(String[] args){

System.out.println("hello world!");

}

}

一. 基本概念

Java是一种可以撰写跨平台应用软件的面向对象的程序设计语言。Java 技术具有卓越的通用性、高效性、平台移植性和安全性,广泛应用于PC、数据中心、游戏控制台、科学超级计算机、移动电话和互联网,同时拥有全球最大的开发者专业社群。

二. 体系

Java分为三个体系,分别为Java SE(J2SE,Java2 Platform Standard Edition,标准版),

JavaEE(J2EE,Java 2 Platform, Enterprise Edition,企业版)。

Java ME(J2ME,Java 2 Platform Micro Edition,微型版)。

求简单JAVA程序代码,能操作的,简单的计算器有计算功能+-*/就行越简单越好!!!急!!!

public static void main(String[] args) {

String st = "";

计算器 j = new 计算器();

boolean t = true;

while (t) {

System.out.print("请输入计算代码:");

BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

try {

st = br.readLine();

} catch (IOException ex) {

Logger.getLogger(计算器.class.getName()).log(Level.SEVERE, null, ex);

}

if (st.equals("end")) {

t = false;

} else if (!st.equals("")) {

j.处理(st);

}

}

}

public void 处理(String st) {

if (st.indexOf("+") != -1) {

加(符号处理(st, "+"));

} else if (st.indexOf("-") != -1) {

减(符号处理(st, "-"));

} else if (st.indexOf("*") != -1) {

乘(符号处理(st, "*"));

} else if (st.indexOf("/") != -1) {

除(符号处理(st, "/"));

}

}

public int[] 符号处理(String st, String s) {

int[] i = new int[2];

i[0] = Integer.parseInt(st.substring(0, st.indexOf(s)));

i[1] = Integer.parseInt(st.substring(st.indexOf(s) + 1));

return i;

}

public void 加(int x[]) {

System.out.println(x[0] + "+" + x[1] + "=" + (x[0] + x[1]));

}

public void 减(int[] x) {

System.out.println(x[0] + "-" + x[1] + "=" + (x[0] - x[1]));

}

public void 乘(int[] x) {

System.out.println(x[0] + "*" + x[1] + "=" + x[0] * x[1]);

}

public void 除(int x[]) {

if (x[1] == 0) {

System.out.print("除数不能为零");

return;

}

System.out.println(x[0] + "/" + x[1] + "=" + x[0] / x[1]);

}

可以运行:输入示例:55+62

一个简单的Java程序代码?

package com.zpp;public class Charge {

public static void main(String [] args) {

if(args.length ==0) {

System.out.println("parameter error!");

System.out.println("java com.zpp.Charge [int]");

return;

}

int min = Integer.parseInt(args[0]);

double money = 0.0;

if (min = 0) {

money =0.0;

System.out.println("not money");

} else if (min = 60) {

money = 2.0;

} else {

money = 2.0 + (min - 60) * 0.01;

}

System.out.println("please pay: " + money);

}

} 编译:javac -d . Charge.java运行:java com.zpp.Charge 111


文章题目:简单的java计算机代码,java编写计算机
当前链接:http://cdkjz.cn/article/dsihghh.html
多年建站经验

多一份参考,总有益处

联系快上网,免费获得专属《策划方案》及报价

咨询相关问题或预约面谈,可以通过以下方式与我们联系

大客户专线   成都:13518219792   座机:028-86922220