真实的国产乱ⅩXXX66竹夫人,五月香六月婷婷激情综合,亚洲日本VA一区二区三区,亚洲精品一区二区三区麻豆

成都創(chuàng)新互聯(lián)網(wǎng)站制作重慶分公司

計蒜客Java代碼大全的簡單介紹

計蒜客練習(xí)題:用java編寫A+B+C的計算結(jié)果

將 string[] args 改成 String[] args。如果是初學(xué)Java,記住,Java 標(biāo)準(zhǔn)使用駝峰命令法,所有類名的首字母都是大寫。好好加油,剛開始學(xué)大家都會犯這些錯誤

十余年的鄂州網(wǎng)站建設(shè)經(jīng)驗(yàn),針對設(shè)計、前端、開發(fā)、售后、文案、推廣等六對一服務(wù),響應(yīng)快,48小時及時工作處理。全網(wǎng)營銷推廣的優(yōu)勢是能夠根據(jù)用戶設(shè)備顯示端的尺寸不同,自動調(diào)整鄂州建站的顯示方式,使網(wǎng)站能夠適用不同顯示終端,在瀏覽器中調(diào)整網(wǎng)站的寬度,無論在任何一種瀏覽器上瀏覽網(wǎng)站,都能展現(xiàn)優(yōu)雅布局與設(shè)計,從而大程度地提升瀏覽體驗(yàn)。創(chuàng)新互聯(lián)從事“鄂州網(wǎng)站設(shè)計”,“鄂州網(wǎng)站推廣”以來,每個客戶項(xiàng)目都認(rèn)真落實(shí)執(zhí)行。

需求50句以上的JAVA代碼,并帶注解

Java文件操作大全

1.創(chuàng)建文件夾

//import java.io.*;

File myFolderPath = new File(%%1);

try {

if (!myFolderPath.exists()) {

myFolderPath.mkdir();

}

}

catch (Exception e) {

System.out.println("新建目錄操作出錯");

e.printStackTrace();

}

2.創(chuàng)建文件

//import java.io.*;

File myFilePath = new File(%%1);

try {

if (!myFilePath.exists()) {

myFilePath.createNewFile();

}

FileWriter resultFile = new FileWriter(myFilePath);

PrintWriter myFile = new PrintWriter(resultFile);

myFile.println(%%2);

resultFile.close();

}

catch (Exception e) {

System.out.println("新建文件操作出錯");

e.printStackTrace();

}

3.刪除文件

//import java.io.*;

File myDelFile = new File(%%1);

try {

myDelFile.delete();

}

catch (Exception e) {

System.out.println("刪除文件操作出錯");

e.printStackTrace();

}

4.刪除文件夾

//import java.io.*;

File delFolderPath = new File(%%1);

try {

delFolderPath.delete(); //刪除空文件夾

}

catch (Exception e) {

System.out.println("刪除文件夾操作出錯");

e.printStackTrace();

}

5.刪除一個文件下夾所有的文件夾

//import java.io.*;

File delfile=new File(%%1);

File[] files=delfile.listFiles();

for(int i=0;ifiles.length;i++){

if(files[i].isDirectory()){

files[i].delete();

}

}

6.清空文件夾

//import java.io.*;

File delfilefolder=new File(%%1);

try {

if (!delfilefolder.exists()) {

delfilefolder.delete();

}

delfilefolder.mkdir();

}

catch (Exception e) {

System.out.println("清空目錄操作出錯");

e.printStackTrace();

}

7.讀取文件

//import java.io.*;

// 逐行讀取數(shù)據(jù)

FileReader fr = new FileReader(%%1);

BufferedReader br = new BufferedReader(fr);

String %%2 = br.readLine();

while (%%2 != null) {

%%3

%%2 = br.readLine();

}

br.close();

fr.close();

8.寫入文件

//import java.io.*;

// 將數(shù)據(jù)寫入文件

try {

FileWriter fw = new FileWriter(%%1);

fw.write(%%2);

fw.flush();

fw.close();

} catch (IOException e) {

e.printStackTrace();

}

9.寫入隨機(jī)文件

//import java.io.*;

try {

RandomAcessFile logFile=new RandomAcessFile(%%1,"rw");

long lg=logFile.length();

logFile.seek(%%2);

logFile.writeByte(%%3);

}catch(IOException ioe){

System.out.println("無法寫入文件:"+ioe.getMessage());

}

10.讀取文件屬性

//import java.io.*;

// 文件屬性的取得

File af = new File(%%1);

if (af.exists()) {

System.out.println(f.getName() + "的屬性如下: 文件長度為:" + f.length());

System.out.println(f.isFile() ? "是文件" : "不是文件");

System.out.println(f.isDirectory() ? "是目錄" : "不是目錄");

System.out.println(f.canRead() ? "可讀取" : "不");

System.out.println(f.canWrite() ? "是隱藏文件" : "");

System.out.println("文件夾的最后修改日期為:" + new Date(f.lastModified()));

} else {

System.out.println(f.getName() + "的屬性如下:");

System.out.println(f.isFile() ? "是文件" : "不是文件");

System.out.println(f.isDirectory() ? "是目錄" : "不是目錄");

System.out.println(f.canRead() ? "可讀取" : "不");

System.out.println(f.canWrite() ? "是隱藏文件" : "");

System.out.println("文件的最后修改日期為:" + new Date(f.lastModified()));

}

if(f.canRead()){

%%2

}

if(f.canWrite()){

%%3

}

11.寫入屬性

//import java.io.*;

File filereadonly=new File(%%1);

try {

boolean b=filereadonly.setReadOnly();

}

catch (Exception e) {

System.out.println("拒絕寫訪問:"+e.printStackTrace());

}

12.枚舉一個文件夾中的所有文件

//import java.io.*;

//import java.util.*;

LinkedListString folderList = new LinkedListString();

folderList.add(%%1);

while (folderList.size() 0) {

File file = new File(folderList.peek());

folderList.removeLast();

File[] files = file.listFiles();

ArrayListFile fileList = new ArrayListFile();

for (int i = 0; i files.length; i++) {

if (files[i].isDirectory()) {

folderList.add(files[i].getPath());

} else {

fileList.add(files[i]);

}

}

for (File f : fileList) {

%%2=f.getAbsoluteFile();

%%3

}

}

13.復(fù)制文件夾

//import java.io.*;

//import java.util.*;

LinkedListString folderList = new LinkedListString();

folderList.add(%%1);

LinkedListString folderList2 = new LinkedListString();

folderList2.add(%%2+ %%1.substring(%%1.lastIndexOf("\\")));

while (folderList.size() 0) {

(new File(folderList2.peek())).mkdirs(); // 如果文件夾不存在 則建立新文件夾

File folders = new File(folderList.peek());

String[] file = folders.list();

File temp = null;

try {

for (int i = 0; i file.length; i++) {

if (folderList.peek().endsWith(File.separator)) {

temp = new File(folderList.peek() + File.separator

+ file[i]);

} else {

temp = new File(folderList.peek() + File.separator

+ file[i]);

}

if (temp.isFile()) {

FileInputStream input = new FileInputStream(temp);

FileOutputStream output = new FileOutputStream(

folderList2.peek() + File.separator

+ (temp.getName()).toString());

byte[] b = new byte[5120];

int len;

while ((len = input.read(b)) != -1) {

output.write(b, 0, len);

}

output.flush();

output.close();

input.close();

}

if (temp.isDirectory()) {// 如果是子文件夾

for (File f : temp.listFiles()) {

if (f.isDirectory()) {

folderList.add(f.getPath());

folderList2.add(folderList2.peek()

+ File.separator + f.getName());

}

}

}

}

} catch (Exception e) {

//System.out.println("復(fù)制整個文件夾內(nèi)容操作出錯");

e.printStackTrace();

}

folderList.removeFirst();

folderList2.removeFirst();

}

14.復(fù)制一個文件夾下所有的文件夾到另一個文件夾下

//import java.io.*;

//import java.util.*;

File copyfolders=new File(%%1);

File[] copyfoldersList=copyfolders.listFiles();

for(int k=0;kcopyfoldersList.length;k++){

if(copyfoldersList[k].isDirectory()){

ArrayListStringfolderList=new ArrayListString();

folderList.add(copyfoldersList[k].getPath());

ArrayListStringfolderList2=new ArrayListString();

folderList2.add(%%2+"/"+copyfoldersList[k].getName());

for(int j=0;jfolderList.length;j++){

(new File(folderList2.get(j))).mkdirs(); //如果文件夾不存在 則建立新文件夾

File folders=new File(folderList.get(j));

String[] file=folders.list();

File temp=null;

try {

for (int i = 0; i file.length; i++) {

if(folderList.get(j).endsWith(File.separator)){

temp=new File(folderList.get(j)+"/"+file[i]);

}

else{

temp=new File(folderList.get(j)+"/"+File.separator+file[i]);

}

FileInputStream input = new FileInputStream(temp);

if(temp.isFile()){

FileInputStream input = new FileInputStream(temp);

FileOutputStream output = new FileOutputStream(folderList2.get(j) + "/" +

(temp.getName()).toString());

byte[] b = new byte[5120];

int len;

while ( (len = input.read(b)) != -1) {

output.write(b, 0, len);

}

output.flush();

output.close();

input.close();

}

if(temp.isDirectory()){//如果是子文件夾

folderList.add(folderList.get(j)+"/"+file[i]);

folderList2.add(folderList2.get(j)+"/"+file[i]);

}

}

}

catch (Exception e) {

System.out.println("復(fù)制整個文件夾內(nèi)容操作出錯");

e.printStackTrace();

}

}

}

}

15.移動文件夾

//import java.io.*;

//import java.util.*;

LinkedListString folderList = new LinkedListString();

folderList.add(%%1);

LinkedListString folderList2 = new LinkedListString();

folderList2.add(%%2 + %%1.substring(%%1.lastIndexOf("\\")));

while (folderList.size() 0) {

(new File(folderList2.peek())).mkdirs(); // 如果文件夾不存在 則建立新文件夾

File folders = new File(folderList.peek());

String[] file = folders.list();

File temp = null;

try {

for (int i = 0; i file.length; i++) {

if (folderList.peek().endsWith(File.separator)) {

temp = new File(folderList.peek() + File.separator

+ file[i]);

} else {

temp = new File(folderList.peek() + File.separator

+ file[i]);

}

if (temp.isFile()) {

FileInputStream input = new FileInputStream(temp);

FileOutputStream output = new FileOutputStream(

folderList2.peek() + File.separator

+ (temp.getName()).toString());

byte[] b = new byte[5120];

int len;

while ((len = input.read(b)) != -1) {

output.write(b, 0, len);

}

output.flush();

output.close();

input.close();

if (!temp.delete())

System.out.println("刪除單個文件操作出錯!");

}

if (temp.isDirectory()) {// 如果是子文件夾

for (File f : temp.listFiles()) {

if (f.isDirectory()) {

folderList.add(f.getPath());

folderList2.add(folderList2.peek()

+ File.separator + f.getName());

}

}

}

}

} catch (Exception e) {

// System.out.println("復(fù)制整個文件夾內(nèi)容操作出錯");

e.printStackTrace();

}

folderList.removeFirst();

folderList2.removeFirst();

}

File f = new File(%%1);

if (!f.delete()) {

for (File file : f.listFiles()) {

if (file.list().length == 0) {

System.out.println(file.getPath());

file.delete();

}

}

}

16.移動一個文件夾下所有的文件夾到另一個目錄下

//import java.io.*;

//import java.util.*;

File movefolders=new File(%%1);

File[] movefoldersList=movefolders.listFiles();

for(int k=0;kmovefoldersList.length;k++){

if(movefoldersList[k].isDirectory()){

ArrayListStringfolderList=new ArrayListString();

folderList.add(movefoldersList[k].getPath());

ArrayListStringfolderList2=new ArrayListString();

folderList2.add(%%2+"/"+movefoldersList[k].getName());

for(int j=0;jfolderList.length;j++){

(new File(folderList2.get(j))).mkdirs(); //如果文件夾不存在 則建立新文件夾

File folders=new File(folderList.get(j));

String[] file=folders.list();

File temp=null;

try {

for (int i = 0; i file.length; i++) {

if(folderList.get(j).endsWith(File.separator)){

temp=new File(folderList.get(j)+"/"+file[i]);

}

else{

temp=new File(folderList.get(j)+"/"+File.separator+file[i]);

}

FileInputStream input = new FileInputStream(temp);

if(temp.isFile()){

FileInputStream input = new FileInputStream(temp);

FileOutputStream output = new FileOutputStream(folderList2.get(j) + "/" +

(temp.getName()).toString());

byte[] b = new byte[5120];

int len;

while ( (len = input.read(b)) != -1) {

output.write(b, 0, len);

}

output.flush();

output.close();

input.close();

temp.delete();

}

if(temp.isDirectory()){//如果是子文件夾

folderList.add(folderList.get(j)+"/"+file[i]);

folderList2.add(folderList2.get(j)+"/"+file[i]);

}

}

}

catch (Exception e) {

System.out.println("復(fù)制整個文件夾內(nèi)容操作出錯");

e.printStackTrace();

}

}

movefoldersList[k].delete();

}

}

17.以一個文件夾的框架在另一個目錄創(chuàng)建文件夾和空文件

//import java.io.*;

//import java.util.*;

boolean b=false;//不創(chuàng)建空文件

ArrayListStringfolderList=new ArrayListString();

folderList.add(%%1);

ArrayListStringfolderList2=new ArrayListString();

folderList2.add(%%2);

for(int j=0;jfolderList.length;j++){

(new File(folderList2.get(j))).mkdirs(); //如果文件夾不存在 則建立新文件夾

File folders=new File(folderList.get(j));

String[] file=folders.list();

File temp=null;

try {

for (int i = 0; i file.length; i++) {

if(folderList.get(j).endsWith(File.separator)){

temp=new File(folderList.get(j)+"/"+file[i]);

}

else{

temp=new File(folderList.get(j)+"/"+File.separator+file[i]);

}

FileInputStream input = new FileInputStream(temp);

if(temp.isFile()){

if (b) temp.createNewFile();

}

if(temp.isDirectory()){//如果是子文件夾

folderList.add(folderList.get(j)+"/"+file[i]);

folderList2.add(folderList2.get(j)+"/"+file[i]);

}

}

}

catch (Exception e) {

System.out.println("復(fù)制整個文件夾內(nèi)容操作出錯");

e.printStackTrace();

}

}

18.復(fù)制文件

//import java.io.*;

int bytesum = 0;

int byteread = 0;

File oldfile = new File(%%1);

try {

if (oldfile.exists()) { //文件存在時

FileInputStream inStream = new FileInputStream(oldfile); //讀入原文件

FileOutputStream fs = new FileOutputStream(new File(%%2,oldfile.getName()));

byte[] buffer = new byte[5120];

int length;

while ( (byteread = inStream.read(buffer)) != -1) {

bytesum += byteread; //字節(jié)數(shù) 文件大小

System.out.println(bytesum);

fs.write(buffer, 0, byteread);

}

inStream.close();

}

}

catch (Exception e) {

System.out.println("復(fù)制單個文件操作出錯");

e.printStackTrace();

}

19.復(fù)制一個文件夾下所有的文件到另一個目錄

//import java.io.*;

File copyfiles=new File(%%1);

File[] files=copyfiles.listFiles();

for(int i=0;ifiles.length;i++){

if(!files[i].isDirectory()){

int bytesum = 0;

int byteread = 0;

try {

InputStream inStream = new FileInputStream(files[i]); //讀入原文件

FileOutputStream fs = new FileOutputStream(new File(%%2,files[i].getName());

byte[] buffer = new byte[5120];

int length;

while ( (byteread = inStream.read(buffer)) != -1) {

bytesum += byteread; //字節(jié)數(shù) 文件大小

System.out.println(bytesum);

fs.write(buffer, 0, byteread);

}

inStream.close();

} catch (Exception e) {

System.out.println("復(fù)制單個文件操作出錯");

e.printStackTrace();

}

}

}

20.提取擴(kuò)展名

String %%2=%%1.substring(%%1.lastIndexOf(".")+1);

要用java編的計算器代碼

給你一個比較簡單的吧。以前寫的。

共兩個類。還只是完成+、-、×、÷運(yùn)算而已。

GUI只是用了AWT,很簡單,相信一看就能懂了。

Calculator.java

public class Calculator{

private String result = "0";

private int op = 0,add = 1,sub = 2,mul = 3,div = 4;

private double stringToDouble(String x){

double y = Double.parseDouble(x);

return y;

}

private void operate(String x){

double x1 = stringToDouble(x);

double y = stringToDouble(result);

switch (op){

case 0:

result = x;

break;

case 1:

result = String.valueOf(y+x1);

break;

case 2:

result = String.valueOf(y-x1);

break;

case 3:

result = String.valueOf(y*x1);

break;

case 4:

if(x1!=0){

result = String.valueOf(y/x1);

}else{

result = "The divisor can't be zero!";

}

break;

}

}

public String opAdd(String x){

operate(x);

op = add;

return result;

}

public String opSubtract(String x){

operate(x);

op = sub;

return result;

}

public String opMultiply(String x){

operate(x);

op = mul;

return result;

}

public String opDivide(String x){

operate(x);

op = div;

return result;

}

public String opEquals(String x){

operate(x);

op = 0;

return result;

}

public void opClean(){

op = 0;

result = "0";

}

}

CalculatorGUI.java

import java.awt.*;

import java.awt.event.*;

import java.util.EventObject;

public class CalculatorGUI{

private Frame f;

private Panel p1,p2;

private Button b0,b1,b2,b3,b4,b5,b6,b7,b8,b9;

private Button bPoint,bAdd,bDec,bMul,bDiv,bCal;

private TextField tf;

private String s,op;

private Calculator cal = new Calculator();

private boolean ifOp;

public CalculatorGUI(){

f = new Frame("Calculator");

p1 = new Panel();

p2 = new Panel();

b0 = new Button("0");

b1 = new Button("1");

b2 = new Button("2");

b3 = new Button("3");

b4 = new Button("4");

b5 = new Button("5");

b6 = new Button("6");

b7 = new Button("7");

b8 = new Button("8");

b9 = new Button("9");

bPoint = new Button(".");

bAdd = new Button("+");

bDec = new Button("-");

bMul = new Button("*");

bDiv = new Button("/");

bCal = new Button("=");

tf = new TextField(25);

tf.setEditable(false);

}

public void launchFrame(){

f.setSize(220,160);

f.setResizable(false);

f.addWindowListener(new myWindowListener());

p1.setLayout(new FlowLayout(FlowLayout.CENTER));

p1.add(tf);

f.add(p1,BorderLayout.NORTH);

p2.setLayout(new GridLayout(4,4));

b0.addActionListener(new setLabelText_ActionListener());

b1.addActionListener(new setLabelText_ActionListener());

b2.addActionListener(new setLabelText_ActionListener());

b3.addActionListener(new setLabelText_ActionListener());

b4.addActionListener(new setLabelText_ActionListener());

b5.addActionListener(new setLabelText_ActionListener());

b6.addActionListener(new setLabelText_ActionListener());

b7.addActionListener(new setLabelText_ActionListener());

b8.addActionListener(new setLabelText_ActionListener());

b9.addActionListener(new setLabelText_ActionListener());

bPoint.addActionListener(new setLabelText_ActionListener());

bAdd.addActionListener(new setOperator_ActionListener());

bDec.addActionListener(new setOperator_ActionListener());

bMul.addActionListener(new setOperator_ActionListener());

bDiv.addActionListener(new setOperator_ActionListener());

bCal.addActionListener(new setOperator_ActionListener());

p2.add(b7);

p2.add(b8);

p2.add(b9);

p2.add(bAdd);

p2.add(b4);

p2.add(b5);

p2.add(b6);

p2.add(bDec);

p2.add(b1);

p2.add(b2);

p2.add(b3);

p2.add(bMul);

p2.add(b0);

p2.add(bPoint);

p2.add(bCal);

p2.add(bDiv);

f.add(p2,BorderLayout.SOUTH);

f.setVisible(true);

}

public void setTextFieldText_Temp(){

if (tf.getText().length()15 (tf.getText().indexOf(".")==-1 || !s.equals("."))){

tf.setText(tf.getText()+s);

}else{

tf.setText((tf.getText()+s).substring(0,15));

}

}

public void setTextFieldText(){

if(ifOp){

ifOp = false;

tf.setText("");

setTextFieldText_Temp();

}else{

setTextFieldText_Temp();

}

}

public static void main(String[] args){

CalculatorGUI calculator = new CalculatorGUI();

calculator.launchFrame();

}

class myWindowListener extends WindowAdapter{

public void windowClosing(WindowEvent e){

System.exit(0);

}

}

class setLabelText_ActionListener implements ActionListener{

public void actionPerformed(ActionEvent e){

Button tempB = (Button)e.getSource();

s = tempB.getLabel();

setTextFieldText();

}

}

class setOperator_ActionListener implements ActionListener{

public void actionPerformed(ActionEvent e){

Button tempB = (Button)e.getSource();

op = tempB.getLabel();

if(op.equals("+")){

tf.setText(cal.opAdd(tf.getText()));

ifOp = true;

}else if(op.equals("-")){

tf.setText(cal.opSubtract(tf.getText()));

ifOp = true;

}else if(op.equals("*")){

tf.setText(cal.opMultiply(tf.getText()));

ifOp = true;

}else if(op.equals("/")){

tf.setText(cal.opDivide(tf.getText()));

ifOp = true;

}else if(op.equals("=")){

tf.setText(cal.opEquals(tf.getText()));

ifOp = true;

}

}

}

}

計蒜客 T1071 計分程序題目,求java解答!

可以使用遞歸,我就寫一個static方法剩下的語句你應(yīng)該會寫

public static int sum(int num)

{int k=0;

if(num=10)k=6;

else if(num10num=20)k=2;

else if(num20num40)k=1;

if(num=40)return 100;

else if(num==1)return 6;//*設(shè)定邊界值1和40**//

else return sum(n-1)+k;

}

給段最簡單的java代碼 讓我新手看一下

最簡單的java代碼肯定就是這個了,如下:

public class MyFirstApp

{

public static void main(String[] args)

{

System.out.print("Hello world");

}

}

“hello world”就是應(yīng)該是所有學(xué)java的新手看的第一個代碼了。如果是零基礎(chǔ)的新手朋友們可以來我們的java實(shí)驗(yàn)班試聽,有免費(fèi)的試聽課程幫助學(xué)習(xí)java必備基礎(chǔ)知識,有助教老師為零基礎(chǔ)的人提供個人學(xué)習(xí)方案,學(xué)習(xí)完成后有考評團(tuán)進(jìn)行專業(yè)測試,幫助測評學(xué)員是否適合繼續(xù)學(xué)習(xí)java,15天內(nèi)免費(fèi)幫助來報名體驗(yàn)實(shí)驗(yàn)班的新手快速入門java,更好的學(xué)習(xí)java!

JAVA計算器代碼

import java.awt.*;

import java.applet.*;

public class CalculatorDemo extends Applet

{

TextField answerText;

Button pointButton,equalButton,plusButton;

Button minusButton,clearButton,multiButton,divisionButton;

Button[] b=new Button[10];

String currentOp,preOp;

String foreText,backText;

boolean isFloat=false;

public void init()

{

Panel p1=new Panel();

Panel p2=new Panel();

Panel p3=new Panel();

currentOp=new String("");

preOp=new String("");

foreText=new String("");

backText=new String("");

answerText=new TextField(8);

setBackground(Color.lightGray);

setForeground(Color.blue);

for(int i=9;i=0;i--)

{

b[i]=new Button(Integer.toString(i));

p2.add(b[i]);

}

pointButton=new Button(".");

equalButton=new Button("=");

equalButton.setForeground(Color.red);

clearButton=new Button("清除");

clearButton.setForeground(Color.red);

divisionButton=new Button("/");

divisionButton.setForeground(Color.red);

multiButton=new Button("*");

multiButton.setForeground(Color.red);

minusButton=new Button("-");

minusButton.setForeground(Color.red);

plusButton=new Button("+");

plusButton.setForeground(Color.red);

setLayout(new FlowLayout());

p1.setLayout(new FlowLayout());

p2.setLayout(new GridLayout(4,3));

p3.setLayout(new GridLayout(4,1));

p1.add(answerText);

p1.add(clearButton);

p2.add(pointButton);

p2.add(equalButton);

p3.add(plusButton);

p3.add(minusButton);

p3.add(multiButton);

p3.add(divisionButton);

add(p1);

add(p2);

add(p3);

}

public boolean action(Event e,Object o)

{

String s=new String("");

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

{

if(e.target==b[i]||e.target==pointButton)

{

if(e.target !=pointButton)

{

s=(String)o;

doForeText(s);

}

if((e.target==pointButton)(!isFloat))

{

isFloat=true;

s=(String)o;

if(foreText.equals(""))

{

foreText +="0.";

}

else

{

doForeText(s);

}

}

}

}

if(e.target==clearButton)

{

doClear();

}

if((e.target==clearButton)||(e.target==divisionButton)

||(e.target==plusButton)||(e.target==minusButton))

{

if(foreText !="")

{

currentOp=((String)o);

doOperator();

}

else

{

preOp=((String)o);

}

}

if(e.target==equalButton)

{

doOperator();

}

return true;

}

public void doOperator()

{

double dFore,dBack;

Double d;

if(preOp.equals(""))

{

backText=foreText;

foreText="";

answerText.setText(backText);

}

else

{

dFore=(new Double(foreText)).doubleValue();

dBack=(new Double(backText)).doubleValue();

foreText="";

backText=answerText.getText();

if(preOp.equals("+"))

{

d=new Double((dBack+dFore));

answerText.setText(d.toString());

backText=d.toString();

}

if(preOp.equals("-"))

{

d=new Double((dBack-dFore));

answerText.setText(d.toString());

backText=d.toString();

}

if(preOp.equals("*"))

{

d=new Double((dBack*dFore));

answerText.setText(d.toString());

backText=d.toString();

}

if(preOp.equals("/"))

{

if(dFore==0)

{

answerText.setText("除數(shù)不能為0");

return;

}

d=new Double((dBack/dFore));

answerText.setText(d.toString());

backText=d.toString();

}

}

preOp=currentOp;

}

public void doForeText(String s)

{

foreText +=s;

answerText.setText(foreText);

}

public void doBackText(String s)

{

backText=foreText;

foreText="";

answerText.setText(foreText);

}

public void doClear()

{

currentOp="";

preOp="";

foreText="";

backText="";

isFloat=false;

answerText.setText("");

}

}


新聞標(biāo)題:計蒜客Java代碼大全的簡單介紹
網(wǎng)頁URL:http://weahome.cn/article/dsgcsss.html

其他資訊

在線咨詢

微信咨詢

電話咨詢

028-86922220(工作日)

18980820575(7×24)

提交需求

返回頂部