资讯

精准传达 • 有效沟通

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

java计算机代码,java计算机代码怎么设置小数点只能打一个

一个简单的Java程序代码?

package com.zpp;public class Charge {

发展壮大离不开广大客户长期以来的信赖与支持,我们将始终秉承“诚信为本、服务至上”的服务理念,坚持“二合一”的优良服务模式,真诚服务每家企业,认真做好每个细节,不断完善自我,成就企业,实现共赢。行业涉及成都房屋鉴定等,在成都网站建设营销型网站建设、WAP手机网站、VI设计、软件开发等项目上具有丰富的设计经验。

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代码的编译与反编译

2017-02-21Hollis数盟

一、什么是编译

1、利用编译程序从源语言编写的源程序产生目标程序的过程。

2、用编译程序产生目标程序的动作。编译就是把高级语言变成计算机可以识别的2进制语言,计算机只认识1和0,编译程序把人们熟悉的语言换成2进制的。编译程序把一个源程序翻译成目标程序的工作过程分为五个阶段:词法分析;语法分析;语义检查和中间代码生成;代码优化;目标代码生成。主要是进行词法分析和语法分析,又称为源程序分析,分析过程中发现有语法错误,给出提示信息。

二、什么是反编译

计算机软件反向工程(Reverseengineering)也称为计算机软件还原工程,是指通过对他人软件的目标程序(可执行程序)进行“逆向分析、研究”工作,以推导出他人的软件产品所使用的思路、原理、结构、算法、处理过程、运行方法等设计要素,某些特定情况下可能推导出源代码。反编译作为自己开发软件时的参考,或者直接用于自己的软件产品中。

三、Java类的编译与反编译

我们在最初学习Java的时候,会接触到两个命令:javac和java,那个时候我们就知道,javac是用来编译Java类的,就是将我们写好的helloworld.java文件编译成helloworld.class文件。

class文件打破了C或者C++等语言所遵循的传统,使用这些传统语言写的程序通常首先被编译,然后被连接成单独的、专门支持特定硬件平台和操作系统的二进制文件。通常情况下,一个平台上的二进制可执行文件不能在其他平台上工作。而Javaclass文件是可以运行在任何支持Java虚拟机的硬件平台和操作系统上的二进制文件。

那么反编译呢,就是通过helloworld.class文件得到java文件(或者说是程序员能看懂的Java文件)

四、什么时候会用到反编译

1、我们只有一个类的class文件,但是我们又看不懂Java的class文件,那么我们可以把它反编译成我们可以看得懂的文件。

2、学习Java过程中,JDK的每个版本都会加入越来越多的语法糖,有些时候我们想知道Java一些实现细节,我们可以借助反编译。

五、反编译工具

1、javap

2、Jad:官网(墙裂推荐)

客户端:

可以在官网下载可执行文件,找到对应的操作系统的对应版本,然后进行安装使用。

因为我使用的是linux操作系统,所以我下载的是Linux版本的工具,这个工具下载好之后会有一个执行文件,只要在执行文件所在目录执行./jadhelloworld.class就会在当前目录下生成helloworld.jad文件,该文件里就是我们很熟悉的Java代码

Eclipse插件:

下载地址在官网下载插件的jar包,然后将jar包放到eclipse的plugins目录下‘在打开Eclipse,Eclipse-Window-Preferences-Java,此时你会发现会比原来多了一个JadClipse的选项,单击,在Pathtodecompiler中输入你刚才放置jad.exe的位置,也可以制定临时文件的目录。当然在JadClipse下还有一些子选项,如Debug,Directives等,按照默认配置即可。基本配置完毕后,我们可以查看一下class文件的默认打开方式,Eclipse-Window-Preferences-General-Editors-FileAssociations我们可以看到class文件的打开方式有两个,JadClipse和Eclipse自带的ClassFileViewer,而JadClipse是默认的。全部配置完成,下面我们可以查看源码了,选择需要查看的类,按F3即可查看源码

Java编写程序代码写在哪?

写在java类文件中。

第一步:在需要添加代码的项目上右击,选择“new”。

第二步:之后选择“class”类,之后在“Name”栏输入“class”类名字。

第三步:点击“Finsh”,之后再java类中编写需要的代码即可。

Java求程序代码

按照你的要求编写的Java程序如下

import java.util.Scanner;

public class S{

public static void main(String[] args){

int n=5;

int[] a=new int[n];

System.out.print("请输入"+n+"个正整数:");

Scanner sc=new Scanner(System.in);

for(int i=0;in;i++){

a[i]=sc.nextInt();

}

System.out.print("其中的偶数为:");

for(int i=0;in;i++){

if(a[i]%2==0){

System.out.print(a[i]+" ");

}

}

}

}

java怎么调试代码?

步骤:

1、在cmd中切换到编写的代码所保存的目录下;

2、在cmd中输入javac然后点空格,再点击文件名和包括后缀名确定后,在存放编写代码的文件下会生成一个class的字节码文件;

3、在cmd中输入java然后点空格,输入第二步中生成的字节码的文件名,不需要后缀名,点击确定即可运行代码。

代码就是程序员用开发工具所支持的语言写出来的源文件,是一组由字符、符号或信号码元以离散形式表示信息的明确的规则体系。计算机代码称为源代码,是相对目标代码和可执行代码而言的。 源代码就是用汇编语言和高级语言写出来的地代码,目标代码是指源代码经过编译程序产生的能被cpu直接识别二进制代码。

java编一个计算器的代码

界面漂亮堪比系统自带计算器,功能完美加减乘除开平方等等全部具备,还有清零按钮,小数点的使用,连加连乘功能完全参考系统官方计算器经过长期调试改进而成,马上拷贝代码拿去试试看吧,绝不后悔!

代码如下:

import java.awt.*;

import java.awt.event.*;

import javax.swing.*;

import java.util.*;

public class Counter {

public static void main(String[] args) {

CounterFrame frame = new CounterFrame();

frame.show();

}

}

class CounterFrame extends JFrame {

public CounterFrame() {

JMenuBar menuBar = new JMenuBar();

JMenu menuFile = new JMenu();

JMenu menuFile1 = new JMenu();

JMenu menuFile2 = new JMenu();

JMenu menuFile3 = new JMenu();

JMenuItem menuFileExit = new JMenuItem();

menuFile.setText("文件");

menuFile1.setText("编辑");

menuFile2.setText("查看");

menuFile3.setText("帮助");

menuFileExit.setText("退出");

menuFileExit.addActionListener

(

new ActionListener() {

public void actionPerformed(ActionEvent e) {

CounterFrame.this.windowClosed();

}

}

);

menuFile.add(menuFileExit);

menuBar.add(menuFile);

menuBar.add(menuFile1);

menuBar.add(menuFile2);

menuBar.add(menuFile3);

setTitle("计算器");

setJMenuBar(menuBar);

setSize(new Dimension(400, 280));

this.getContentPane().add(new Allpanel());

this.addWindowListener

(

new WindowAdapter() {

public void windowClosing(WindowEvent e) {

CounterFrame.this.windowClosed();

}

}

);

}

protected void windowClosed() {

System.exit(0);

}

}

class Tool {

public static Tool instance;

private JTextField field;

private Tool() {

this.field=new JTextField(30);

this.field.setHorizontalAlignment(JTextField.RIGHT);

}

public static Tool getinstance()

{

if(instance==null)

{

instance=new Tool();

}

return instance;

}

public JTextField getfield()

{

return (this.field);

}

}

class Allpanel extends JPanel {

public Allpanel() {

this.setLayout(new BorderLayout(0,7));

Northpanel np=new Northpanel();

Centerpanel cp=new Centerpanel();

this.add(np,BorderLayout.NORTH);

this.add(cp,BorderLayout.CENTER);

}

}

class Centercenter extends JPanel {

static Vector Vec=new Vector();

static Vector vc=new Vector();

static Vector vc1=new Vector();

static Vector vc2=new Vector();

static Vector vc3=new Vector();

static String begin="yes";

static double add;

static double jq;

static double cs;

static double cq;

static double dy;

static String jg;

static String what;

static double tool=0;

static String to="yes";

/**

* Method Centercenter

*

*

*/

public Centercenter() {

// TODO: Add your code here

final JTextField text=Tool.getinstance().getfield();

this.setLayout(new GridLayout(4,5,3,3));

String arg[] ={"7","8","9","/","sqrt","4","5","6","*","%","1","2","3","-","1/x","0","+/-",".","+","="};

for(int i=0;i20;i++)

{

final JButton b=new JButton(arg[i]);

//this.add(new JButton(arg[i]));

this.add(b);

if(i==0||i==1||i==2||i==5||i==6||i==7||i==10||i==11||i==12||i==15)

{

b.addActionListener(new ActionListener()

{

public void actionPerformed(ActionEvent e)

{

String mark=b.getText();

String ma=text.getText();

if(vc3.contains("v3"))

{

text.setText("0."+mark);

vc3.clear();

}

else if(vc.contains("a"))

{

if(vc2.contains("v2"))

{

text.setText("0."+mark);

vc.clear();

vc2.clear();

}

else

{

text.setText(mark);

vc.clear();

Vec.clear();

Vec.add(mark);

}

}

else

{

text.setText(ma.trim()+mark);

Vec.add(mark);

}

begin="no";

to="yes";

}

});

}

if(i==17)

{

b.addActionListener(new ActionListener()

{

public void actionPerformed(ActionEvent e)

{

String mar=b.getText();

String m=text.getText();

if("yes".equals(begin))

{

vc3.add("v3");

}

if(vc1.contains("v1"))

{

vc2.add("v2");

vc1.clear();

}

if(!Vec.contains(".")!vc.contains("a"))

{

text.setText(m.trim()+mar);

Vec.add(".");

}

}

});

}

if(i==18)

{

b.addActionListener(new ActionListener()

{

public void actionPerformed(ActionEvent e)

{

String ma=text.getText();

add=Double.parseDouble(ma);

if(what==null)

{

tool=add;

what="add";

}

else

{

tool=tool+add;

text.setText(String.valueOf((tool)));

}

vc.add("a");

vc1.add("v1");

to="+";

}

});

}

if(i==13)

{

b.addActionListener(new ActionListener()

{

public void actionPerformed(ActionEvent e)

{

String ma=text.getText();

jq=Double.parseDouble(ma);

if(what==null)

{

tool=jq;

what="jq";

}

else

{

tool=tool-jq;

text.setText(String.valueOf((tool)));

}

vc.add("a");

vc1.add("v1");

to="-";

}

});

}

if(i==3)

{

b.addActionListener(new ActionListener()

{

public void actionPerformed(ActionEvent e)

{

String ma=text.getText();

cq=Double.parseDouble(ma);

if(what==null)

{

tool=cq;

what="cq";

}

else

{

tool=tool/cq;

text.setText(String.valueOf((tool)));

}

vc.add("a");

vc1.add("v1");

to="/";

}

});

}

if(i==4)

{

b.addActionListener(new ActionListener()

{

public void actionPerformed(ActionEvent e)

{

String ma=text.getText();

cq=Double.parseDouble(ma);

text.setText(String.valueOf(Math.sqrt(cq)));

}

});

}

if(i==8)

{

b.addActionListener(new ActionListener()

{

public void actionPerformed(ActionEvent e)

{

String ma=text.getText();

cs=Double.parseDouble(ma);

if(what==null)

{

tool=cs;

what="cs";

}

else

{

tool=tool*cs;

text.setText(String.valueOf((tool)));

}

vc.add("a");

vc1.add("v1");

to="*";

}

});

}

if(i==19)

{

b.addActionListener(new ActionListener()

{

public void actionPerformed(ActionEvent e)

{

String ma=text.getText();

dy=Double.parseDouble(ma);

if(what=="add")

{

jg=String.valueOf((tool+dy));

}

if(what=="jq")

{

jg=String.valueOf((tool-dy));

}

if(what=="cs")

{

jg=String.valueOf((tool*dy));

}

if(what=="cq")

{

jg=String.valueOf((tool/dy));

}

if(what==null)

{

if(to=="+")

{

tool=add;

jg=String.valueOf(tool+dy);

}

else if(to=="-")

{

tool=jq;

jg=String.valueOf(dy-tool);

}

else if(to=="*")

{

tool=cs;

jg=String.valueOf(dy*tool);

}

else if(to=="/")

{

tool=cq;

jg=String.valueOf(dy/tool);

}

else

{

jg=String.valueOf(dy);

}

}

text.setText(jg);

Vec.clear();

Vec.add(".");

vc.add("a");

vc1.add("v1");

what=null;

tool=0;

}

});

}

}

}

}

class Centernorth extends JPanel {

public Centernorth() {

final JTextField text=Tool.getinstance().getfield();

JButton jb1=new JButton("Backspace");

JButton jb2=new JButton(" CE ");

JButton jb3=new JButton(" C ");

this.add(jb1);

this.add(jb2);

this.add(jb3);

jb1.addActionListener(new ActionListener(){

public void actionPerformed(ActionEvent e)

{

String back=Tool.getinstance().getfield().getText();

text.setText(backmethod(back));

Centercenter.Vec.remove(Centercenter.Vec.size()-1);

}

});

jb3.addActionListener(new ActionListener(){

public void actionPerformed(ActionEvent e)

{

text.setText("0.");

Centercenter.Vec.clear();

Centercenter.Vec.add(".");

Centercenter.vc.add("a");

Centercenter.begin="yes";

Centercenter.vc1.clear();

Centercenter.what=null;

Centercenter.tool=0;

}

});

}

public String backmethod(String str)

{

return str.substring(0,str.length()-1);

}

}

class Centerpanel extends JPanel {

public Centerpanel() {

this.setLayout(new BorderLayout(8,7));

Centernorth cn=new Centernorth();

Centercenter cc=new Centercenter();

Centerwest cw=new Centerwest();

this.add(cn,BorderLayout.NORTH);

this.add(cc,BorderLayout.CENTER);

this.add(cw,BorderLayout.WEST);

}

}

class Centerwest extends JPanel {

public Centerwest() {

this.setLayout(new GridLayout(4,1,3,3));

this.add(new JButton("MC"));

this.add(new JButton("MR"));

this.add(new JButton("MS"));

this.add(new JButton("M+"));

}

}

class Northpanel extends JPanel {

private JTextField tf;

public Northpanel() {

tf=Tool.getinstance().getfield();

this.add(tf);

}

}

---------------------------------------------------------------------------

=============《按你要求特意后改过的最简单功能的代码如下》========================

import java.awt.*;

import java.awt.event.*;

import javax.swing.*;

import java.util.*;

public class Counter2 {

public static void main(String[] args) {

CounterFrame frame = new CounterFrame();

frame.show();

}

}

class CounterFrame extends JFrame {

public CounterFrame() {

setTitle("计算器");

setSize(new Dimension(400, 280));

this.getContentPane().add(new Allpanel());

this.addWindowListener

(

new WindowAdapter() {

public void windowClosing(WindowEvent e) {

CounterFrame.this.windowClosed();

}

}

);

}

protected void windowClosed() {

System.exit(0);

}

}

class Tool {

public static Tool instance;

private JTextField field;

private Tool() {

this.field=new JTextField(30);

this.field.setHorizontalAlignment(JTextField.RIGHT);

}

public static Tool getinstance()

{

if(instance==null)

{

instance=new Tool();

}

return instance;

}

public JTextField getfield()

{

return (this.field);

}

}

class Allpanel extends JPanel {

public Allpanel() {

this.setLayout(new BorderLayout(0,7));

Northpanel np=new Northpanel();

Centerpanel cp=new Centerpanel();

this.add(np,BorderLayout.NORTH);

this.add(cp,BorderLayout.CENTER);

}

}

class Centercenter extends JPanel {

static Vector Vec=new Vector();

static Vector vc=new Vector();

static Vector vc1=new Vector();

static Vector vc2=new Vector();

static Vector vc3=new Vector();

static String begin="yes";

static double add;

static double jq;

static double cs;

static double cq;

static double dy;

static String jg;

static String what;

static double tool=0;

static String to="yes";

/**

* Method Centercenter

*

*

*/

public Centercenter() {

// TODO: Add your code here

final JTextField text=Tool.getinstance().getfield();

this.setLayout(new GridLayout(4,5,3,3));

String arg[] ={"7","8","9","/","4","5","6","*","1","2","3","-","0","=",".","+"};

for(int i=0;i16;i++)

{

final JButton b=new JButton(arg[i]);

//this.add(new JButton(arg[i]));

this.add(b);

if(i==0||i==1||i==2||i==4||i==5||i==6||i==8||i==9||i==10||i==12)

{

b.addActionListener(new ActionListener()

{

public void actionPerformed(ActionEvent e)

{

String mark=b.getText();

String ma=text.getText();

if(vc3.contains("v3"))

{

text.setText("0."+mark);

vc3.clear();

}

else if(vc.contains("a"))

{

if(vc2.contains("v2"))

{

text.setText("0."+mark);

vc.clear();

vc2.clear();

}

else

{

text.setText(mark);

vc.clear();

Vec.clear();

Vec.add(mark);

}

}

else

{

text.setText(ma.trim()+mark);

Vec.add(mark);

}

begin="no";

to="yes";

}

});

}

if(i==14)

{

b.addActionListener(new ActionListener()

{

public void actionPerformed(ActionEvent e)

{

String mar=b.getText();

String m=text.getText();

if("yes".equals(begin))

{

vc3.add("v3");

}

if(vc1.contains("v1"))

{

vc2.add("v2");

vc1.clear();

}

if(!Vec.contains(".")!vc.contains("a"))

{

text.setText(m.trim()+mar);

Vec.add(".");

}

}

});

}

if(i==15)

{

b.addActionListener(new ActionListener()

{

public void actionPerformed(ActionEvent e)

{

String ma=text.getText();

add=Double.parseDouble(ma);

if(what==null)

{

tool=add;

what="add";

}

else

{

tool=tool+add;

text.setText(String.valueOf((tool)));

}

vc.add("a");

vc1.add("v1");

to="+";

}

});

}

if(i==11)

{

b.addActionListener(new ActionListener()

{

public void actionPerformed(ActionEvent e)

{

String ma=text.getText();

jq=Double.parseDouble(ma);

if(what==null)

{

tool=jq;

what="jq";

}

else

{

tool=tool-jq;

text.setText(String.valueOf((tool)));

}

vc.add("a");

vc1.add("v1");

to="-";

}

});

}

if(i==3)

{

b.addActionListener(new ActionListener()

{

public void actionPerformed(ActionEvent e)

{

String ma=text.getText();

cq=Double.parseDouble(ma);

if(what==null)

{

tool=cq;

what="cq";

}

else

{

tool=tool/cq;

text.setText(String.valueOf((tool)));

}

vc.add("a");

vc1.add("v1");

to="/";

}

});

}

if(i==7)

{

b.addActionListener(new ActionListener()

{

public void actionPerformed(ActionEvent e)

{

String ma=text.getText();

cs=Double.parseDouble(ma);

if(what==null)

{

tool=cs;

what="cs";

}

else

{

tool=tool*cs;

text.setText(String.valueOf((tool)));

}

vc.add("a");

vc1.add("v1");

to="*";

}

});

}

if(i==13)

{

b.addActionListener(new ActionListener()

{

public void actionPerformed(ActionEvent e)

{

String ma=text.getText();

dy=Double.parseDouble(ma);

if(what=="add")

{

jg=String.valueOf((tool+dy));

}

if(what=="jq")

{

jg=String.valueOf((tool-dy));

}

if(what=="cs")

{

jg=String.valueOf((tool*dy));

}

if(what=="cq")

{

jg=String.valueOf((tool/dy));

}

if(what==null)

{

if(to=="+")

{

tool=add;

jg=String.valueOf(tool+dy);

}

else if(to=="-")

{

tool=jq;

jg=String.valueOf(dy-tool);

}

else if(to=="*")

{

tool=cs;

jg=String.valueOf(dy*tool);

}

else if(to=="/")

{

tool=cq;

jg=String.valueOf(dy/tool);

}

else

{

jg=String.valueOf(dy);

}

}

text.setText(jg);

Vec.clear();

Vec.add(".");

vc.add("a");

vc1.add("v1");

what=null;

tool=0;

}

});

}

}

}

}

class Centernorth extends JPanel {

public Centernorth() {

final JTextField text=Tool.getinstance().getfield();

}

}

class Centerpanel extends JPanel {

public Centerpanel() {

this.setLayout(new BorderLayout(8,7));

Centernorth cn=new Centernorth();

Centercenter cc=new Centercenter();

Centerwest cw=new Centerwest();

this.add(cn,BorderLayout.NORTH);

this.add(cc,BorderLayout.CENTER);

this.add(cw,BorderLayout.WEST);

}

}

class Centerwest extends JPanel {

public Centerwest() {

}

}

class Northpanel extends JPanel {

private JTextField tf;

public Northpanel() {

tf=Tool.getinstance().getfield();

this.add(tf);

}

}

------------------------------------------------------------

才子_辉祝您愉快!


分享文章:java计算机代码,java计算机代码怎么设置小数点只能打一个
网站网址:http://cdkjz.cn/article/hdhgpp.html
多年建站经验

多一份参考,总有益处

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

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

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