<em>Mac</em>Book项目 2009年学校开始实施<em>Mac</em>Book项目,所有师生配备一本<em>Mac</em>Book,并同步更新了校园无线网络。学校每周进行电脑技术更新,每月发送技术支持资料,极大改变了教学及学习方式。因此2011
2021-06-01 09:32:01
用AndroidStudio編寫高階計算器帶三角函數對數運算功能
介面效果圖:
layout佈局 activity_jisuanqi.xml程式碼:
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" android:padding="5dp" > <LinearLayout android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_weight="2" android:orientation="vertical" > <LinearLayout android:layout_width="fill_parent" android:layout_height="100dp" android:layout_weight="1" android:orientation="vertical" android:paddingBottom="5dp" > <TextView android:id="@+id/text0" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_weight="1.2" android:gravity="right" android:scrollHorizontally="true" android:textColor="#ff000000" android:textSize="25sp" /> <TextView android:id="@+id/text1" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_weight="1" android:gravity="right" android:scrollHorizontally="true" android:text="0" android:textColor="#ff000000" android:textSize="30sp" /> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="21dp" android:layout_weight="1" android:orientation="vertical" > </LinearLayout> </LinearLayout> <LinearLayout android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_weight="1" android:orientation="vertical"> <LinearLayout android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_weight="1" android:orientation="horizontal"> <Button android:id="@+id/factorial" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_weight="1" android:text="!" /> <Button android:id="@+id/power" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_weight="1" android:text="^" /> <Button android:id="@+id/square_root" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_weight="1" android:text="√" /> <Button android:id="@+id/pai" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_weight="1" android:textAllCaps="false" android:text="π" /> <Button android:id="@+id/c" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_weight="1" android:textAllCaps="false" android:text="C" android:textColor="#ffff0000" /> </LinearLayout> <LinearLayout android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_weight="1" android:orientation="horizontal"> <Button android:id="@+id/sin" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_weight="1" android:textAllCaps="false" android:text="sin" /> <Button android:id="@+id/brackets1" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_weight="1" android:text="(" /> <Button android:id="@+id/brackets2" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_weight="1" android:text=")" /> <Button android:id="@+id/e" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_weight="1" android:textAllCaps="false" android:text="e" /> <Button android:id="@+id/del" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_weight="1" android:text="DEL" /> </LinearLayout> <LinearLayout android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_weight="1" android:orientation="horizontal"> <Button android:id="@+id/cos" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_weight="1" android:textAllCaps="false" android:text="cos" /> <Button android:id="@+id/seven" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_weight="1" android:text="7" /> <Button android:id="@+id/eight" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_weight="1" android:text="8" /> <Button android:id="@+id/nine" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_weight="1" android:text="9" /> <Button android:id="@+id/division" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_weight="1" android:text="÷" /> </LinearLayout> <LinearLayout android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_weight="1" android:orientation="horizontal"> <Button android:id="@+id/tan" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_weight="1" android:textAllCaps="false" android:text="tan" /> <Button android:id="@+id/four" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_weight="1" android:text="4" /> <Button android:id="@+id/five" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_weight="1" android:text="5" /> <Button android:id="@+id/six" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_weight="1" android:text="6" /> <Button android:id="@+id/multiple" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_weight="1" android:text="×" /> </LinearLayout> <LinearLayout android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_weight="1" android:orientation="horizontal"> <Button android:id="@+id/ln" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_weight="1" android:textAllCaps="false" android:text="ln" /> <Button android:id="@+id/one" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_weight="1" android:text="1" /> <Button android:id="@+id/two" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_weight="1" android:text="2" /> <Button android:id="@+id/three" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_weight="1" android:text="3" /> <Button android:id="@+id/subtract" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_weight="1" android:text="-" /> </LinearLayout> <LinearLayout android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_weight="1" android:orientation="horizontal"> <Button android:id="@+id/log" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_weight="1" android:textAllCaps="false" android:text="log" /> <Button android:id="@+id/zero" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_weight="1" android:text="0" /> <Button android:id="@+id/point" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_weight="1" android:text="." /> <Button android:id="@+id/add" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_weight="1" android:text="+" /> <Button android:id="@+id/eq" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_weight="1" android:text="=" /> </LinearLayout> </LinearLayout> </LinearLayout>
java類JisuanqiActivity程式碼:
package com.xueba.jsq; import android.app.Activity; import android.os.Bundle; import android.view.Menu; import android.view.MenuItem; import android.view.MenuItem.OnMenuItemClickListener; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.TextView; public class JisuanqiActivity extends Activity implements OnClickListener { /** Called when the activity is first created. */ private String string = "0"; private Button btn1, btn2, btn3, btn4, btn5, btn6, btn7, btn8, btn9, btn0; private Button btnadd, btnsub, btnmul, btndiv, btnsin, btncos, btntan; private Button btnln, btnlog, btne, btneq, btnpoint, btndel, btnpower; private Button btnsq, btnpai, btnc, btnb1, btnb2, btnfa; private TextView btnt0, btnt1; private boolean flag = false; private GetValue getValue = new GetValue(); private Judge judge = new Judge(); private void init() { btn1 = (Button) this.findViewById(R.id.one); btn2 = (Button) this.findViewById(R.id.two); btn3 = (Button) this.findViewById(R.id.three); btn4 = (Button) this.findViewById(R.id.four); btn5 = (Button) this.findViewById(R.id.five); btn6 = (Button) this.findViewById(R.id.six); btn7 = (Button) this.findViewById(R.id.seven); btn8 = (Button) this.findViewById(R.id.eight); btn9 = (Button) this.findViewById(R.id.nine); btn0 = (Button) this.findViewById(R.id.zero); btnadd = (Button) this.findViewById(R.id.add); btnsub = (Button) this.findViewById(R.id.subtract); btnmul = (Button) this.findViewById(R.id.multiple); btndiv = (Button) this.findViewById(R.id.division); btnsin = (Button) this.findViewById(R.id.sin); btncos = (Button) this.findViewById(R.id.cos); btntan = (Button) this.findViewById(R.id.tan); btnln = (Button) this.findViewById(R.id.ln); btnlog = (Button) this.findViewById(R.id.log); btne = (Button) this.findViewById(R.id.e); btneq = (Button) this.findViewById(R.id.eq); btnpoint = (Button) this.findViewById(R.id.point); btndel = (Button) this.findViewById(R.id.del); btnpower = (Button) this.findViewById(R.id.power); btnfa = (Button) this.findViewById(R.id.factorial); btnsq = (Button) this.findViewById(R.id.square_root); btnpai = (Button) this.findViewById(R.id.pai); btnc = (Button) this.findViewById(R.id.c); btnb1 = (Button) this.findViewById(R.id.brackets1); btnb2 = (Button) this.findViewById(R.id.brackets2); btnt0 = (TextView) this.findViewById(R.id.text0); btnt1 = (TextView) this.findViewById(R.id.text1); this.btn0.setOnClickListener(this); this.btn1.setOnClickListener(this); this.btn2.setOnClickListener(this); this.btn3.setOnClickListener(this); this.btn4.setOnClickListener(this); this.btn5.setOnClickListener(this); this.btn6.setOnClickListener(this); this.btn7.setOnClickListener(this); this.btn8.setOnClickListener(this); this.btn9.setOnClickListener(this); this.btnadd.setOnClickListener(this); this.btnb1.setOnClickListener(this); this.btnb2.setOnClickListener(this); this.btnc.setOnClickListener(this); this.btncos.setOnClickListener(this); this.btndel.setOnClickListener(this); this.btndiv.setOnClickListener(this); this.btne.setOnClickListener(this); this.btneq.setOnClickListener(this); this.btnfa.setOnClickListener(this); this.btnln.setOnClickListener(this); this.btnlog.setOnClickListener(this); this.btnmul.setOnClickListener(this); this.btnpai.setOnClickListener(this); this.btnpoint.setOnClickListener(this); this.btnpower.setOnClickListener(this); this.btnsin.setOnClickListener(this); this.btnsq.setOnClickListener(this); this.btnsub.setOnClickListener(this); this.btntan.setOnClickListener(this); } @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_jisuanqi); this.init(); } public boolean onCreateOptionsMenu(Menu menu) { MenuItem exit = menu.add("EXIT"); exit.setOnMenuItemClickListener(new OnMenuItemClickListener() { @Override public boolean onMenuItemClick(MenuItem item) { finish(); return true; } }); return true; } @Override public void onClick(View v) { if ("error".equals(btnt1.getText().toString()) || "∞".equals(btnt1.getText().toString())) { string = "0"; } if (v == this.btn0) { string = judge.digit_judge(string, "0", flag); flag = false; btnt1.setText(string); } else if (v == this.btn1) { string = judge.digit_judge(string, "1", flag); flag = false; btnt1.setText(string); } else if (v == this.btn2) { string = judge.digit_judge(string, "2", flag); flag = false; btnt1.setText(string); } else if (v == this.btn3) { string = judge.digit_judge(string, "3", flag); flag = false; btnt1.setText(string); } else if (v == this.btn4) { string = judge.digit_judge(string, "4", flag); flag = false; btnt1.setText(string); } else if (v == this.btn5) { string = judge.digit_judge(string, "5", flag); flag = false; btnt1.setText(string); } else if (v == this.btn6) { string = judge.digit_judge(string, "6", flag); flag = false; btnt1.setText(string); } else if (v == this.btn7) { string = judge.digit_judge(string, "7", flag); flag = false; btnt1.setText(string); } else if (v == this.btn8) { string = judge.digit_judge(string, "8", flag); flag = false; btnt1.setText(string); } else if (v == this.btn9) { string = judge.digit_judge(string, "9", flag); flag = false; btnt1.setText(string); } else if (v == this.btneq) { btnt0.setText(string + "="); string = getValue.advanced_dispose(string); string = judge.digit_dispose(string); flag = true; btnt1.setText(string); } else if (v == this.btnadd) { string = judge.judge(string, "+"); flag = false; btnt1.setText(string); } else if (v == this.btnsub) { string = judge.judge(string, "-"); flag = false; btnt1.setText(string); } else if (v == this.btnmul) { string = judge.judge(string, "×"); flag = false; btnt1.setText(string); } else if (v == this.btndiv) { string = judge.judge(string, "÷"); flag = false; btnt1.setText(string); } else if (v == this.btnb1) { if ("0".equals(string) || flag) { string = "("; } else string += "("; flag = false; btnt1.setText(string); } else if (v == this.btnb2) { if ("0".equals(string) || flag) { string = ")"; } else string += ")"; flag = false; btnt1.setText(string); } else if (v == this.btne) { if ("0".equals(string)) { string = "e"; } else string += "e"; flag = false; btnt1.setText(string); } else if (v == this.btnpower) { string += "^"; flag = false; btnt1.setText(string); } else if (v == this.btnfa) { string += "!"; flag = false; btnt1.setText(string); } else if (v == this.btnsq) { if ("0".equals(string) || flag) string = ""; string += "√"; flag = false; btnt1.setText(string); } else if (v == this.btnpai) { if ("0".equals(string) || flag) { string = "π"; } else string += "π"; flag = false; btnt1.setText(string); } else if (v == this.btnsin) { if ("0".equals(string) || flag) { string = "sin("; } else string += "sin("; flag = false; btnt1.setText(string); } else if (v == this.btncos) { if ("0".equals(string) || flag) { string = "cos("; } else string += "cos("; flag = false; btnt1.setText(string); } else if (v == this.btntan) { if ("0".equals(string) || flag) { string = "tan("; } else string += "tan("; flag = false; btnt1.setText(string); } else if (v == this.btnln) { if ("0".equals(string) || flag) { string = "ln("; } else string += "ln("; flag = false; btnt1.setText(string); } else if (v == this.btnpoint) { string = judge.judge1(string); flag = false; btnt1.setText(string); } else if (v == this.btnlog) { if ("0".equals(string) || flag) { string = "log("; } else string += "log("; flag = false; btnt1.setText(string); } else if (v == this.btndel) { if (flag) { string = ""; btnt0.setText(string); string = "0"; btnt1.setText(string); } if (!"0".equals(string)) { string = string.substring(0, string.length() - 1); if (0 == string.length()) string = "0"; } flag = false; btnt1.setText(string); } else if (v == this.btnc) { string = ""; btnt0.setText(string); string = "0"; btnt1.setText(string); flag = false; } } }
java類GetValue程式碼:
package com.xueba.jsq; import java.util.LinkedList; import java.util.List; public class GetValue { public String bracke_dispose(String string) { // 處理括號裡的表示式,思路, // 1.遇到正括號就將它在字串裡的索引儲存在一個連結串列裡<插在連結串列頭> // 2.遇到第一個反括號就處理這個括號裡的表示式<取出連結串列第一個元素,然後根據這兩個索引取出表示式,會呼叫一個專門處理 // log,ln,sin,cos,tan等的special_dispose函數,將反回一個自由加減乘除的表示式,在呼叫alg_dispose函數> // 3.函數處理後返回一個可能還含有log,ln,sin,cos,tan等的但沒有括號的表示式; int flag = 0, flag1 = 0, i = 0; int leng = string.length(); List<Integer> list = new LinkedList<Integer>(); Character c; String str = "", tmp = "", tmp3 = "", tmp4 = ""; while (true) { if (i >= leng) break; c = string.charAt(i); if ('(' == c) list.add(0, i); if (')' == c) { if (0 == list.size()) { System.out.println(")error"); return "error"; } str = string.substring(list.get(0) + 1, i); tmp = this.special_dispose(str); tmp = this.alg_dispose(str); if ("error".equals(tmp)) return "error"; tmp3 = string.substring(0, list.get(0)); tmp4 = string.substring(i + 1, leng); string = tmp3 + tmp + tmp4; flag = str.length() + 2; flag1 = tmp.length(); leng += (flag1 - flag); i += (flag1 - flag); list.remove(0); } i++; } if (list.size() != 0) { System.out.println("(error"); return "error"; } return string; } public String special_dispose(String string) { // 用於處理特殊表示式; if ("error".equals(string)) { return "error"; } string = dispose(string, "sin"); string = dispose(string, "cos"); string = dispose(string, "tan"); string = dispose(string, "log"); string = dispose(string, "ln"); string = dispose(string, "!"); string = dispose(string, "^"); string = dispose(string, "√"); string = dispose(string, "e"); return string; } public String alg_dispose(String string) { // 處理加減乘除 string = special_dispose(string); if ("error".equals(string)) { return "error"; } Character c; String str = ""; List<Double> list = new LinkedList<Double>(); double tmp = 0; boolean add_flag = false; for (int i = 0; i < string.length(); i++) { c = string.charAt(i); if (!Judge.paiduan(c)) { str += c; } else { if (str.length() != 0) list.add(new Double(str)); str = ""; switch (c) { case '+': if (2 == list.size()) { if (add_flag) { tmp = list.get(0) + list.get(1); list.clear(); list.add(tmp); } else { tmp = list.get(0) - list.get(1); list.clear(); list.add(tmp); } break; } add_flag = true; break; case '-': if (2 == list.size()) { if (add_flag) { tmp = list.get(0) + list.get(1); list.clear(); list.add(tmp); } else { tmp = list.get(0) - list.get(1); list.clear(); list.add(tmp); } add_flag = false; break; } break; case '×': if (i == (string.length() - 1)) return "error"; while (!(i == (string.length() - 1)) && !Judge.paiduan((c = string.charAt(i + 1)))) { str += c; i++; } if (str.length() != 0) list.add(new Double(str)); str = ""; if (list.size() == 2) { tmp = list.get(0) * list.get(1); list.clear(); list.add(0, tmp); } else { tmp = list.get(2) * list.get(1); list.remove(2); list.remove(1); list.add(tmp); } break; case '÷': if (i == (string.length() - 1)) return "error"; while (!(i == (string.length() - 1)) && !Judge.paiduan((c = string.charAt(i + 1)))) { str += c; i++; } if (str.length() != 0) list.add(new Double(str)); str = ""; if (list.size() == 2) { tmp = list.get(0) / list.get(1); list.clear(); list.add(0, tmp); } else { tmp = list.get(2) / list.get(1); list.remove(2); list.remove(1); list.add(tmp); } break; default: break; } } } if (str.length() != 0) list.add(new Double(str)); if (2 == list.size()) { if (add_flag) { tmp = list.get(0) + list.get(1); list.clear(); list.add(tmp); } else { tmp = list.get(0) - list.get(1); list.clear(); list.add(tmp); } } if (list.size() != 0) string = "" + list.get(0); return string; } public String get_r_digit(String string, int index) { // 得到index右邊的第一個數; String tmp = ""; int length = string.length(), j = index; Character character; if (index >= length) tmp = "error"; while (true) { if (j == length) break; character = string.charAt(j); if (Character.isDigit(character) || (character == '.')) { tmp += character; } else break; j++; } if (0 == tmp.length()) tmp = "error"; System.out.println(tmp); return tmp; } public String get_l_digit(String string, int index) { // 得到index左邊的第一個數; String tmp = ""; int j = index; Character c; if (index < 0) tmp = "error"; while (true) { if (j < 0) break; c = string.charAt(j); if (Character.isDigit(c) || (c == '.')) { tmp = "" + c + tmp; } else break; j--; } if (0 == tmp.length()) tmp = "error"; return tmp; } public String dispose1(String string) { // 將π替換為對應的數位; int index, leng = string.length(); double tmp = Math.PI; while (leng != 0) { index = string.indexOf("π"); if (-1 == index) break; if ((index != 0 && (index + 1) != leng) && Character.isDigit(string.charAt(index + 1)) && Character.isDigit(string.charAt(index - 1))) { string = string.replaceFirst("π", "×" + tmp + "×"); } else if (index != 0 && Character.isDigit(string.charAt(index - 1))) { string = string.replaceFirst("π", "×" + tmp); } else if (index != 0 && Character.isDigit(string.charAt(index + 1))) { string = string.replaceFirst("π", "" + tmp + "×"); } else { string = string.replaceFirst("π", "" + tmp); } } return string; } public String dispose(String string, String dispose) { // 處理指定運運算元;<log,ln,sin,cos,tan....> int index, flag = dispose.length(), flag1, flag2; String tmpString = "", tmpString1 = "", tmpString2 = ""; Double tmp, tmp1; while (string.length() != 0) { index = string.indexOf(dispose); if (-1 == index) break; if ("!".equals(dispose)) { tmpString = get_l_digit(string, index - flag); if (!"error".equals(tmpString) && !"error".equals(tmpString1)) { tmp = new Double(tmpString); } else { return "error"; } tmp1 = 1.0; for (int i = 1; i <= tmp; i++) { tmp1 *= i; } tmpString2 = "" + tmp1; string = string.replaceFirst(tmpString + dispose, tmpString2); } else if ("e".equals(dispose)) { tmpString = get_r_digit(string, index + flag); tmpString1 = get_l_digit(string, index - flag); if (!"error".equals(tmpString) && !"error".equals(tmpString1)) { tmp = new Double(tmpString); tmp1 = new Double(tmpString1); } else { return "error"; } tmp = Math.pow(10, tmp); tmp1 *= tmp; tmpString2 = "" + tmp1; string = string.replaceFirst(tmpString1 + dispose + tmpString, tmpString2); System.out.println(string); } else if ("^".equals(dispose)) { tmpString = get_r_digit(string, index + flag); tmpString1 = get_l_digit(string, index - flag); flag1 = tmpString.length(); flag2 = tmpString1.length(); if (!"error".equals(tmpString) && !"error".equals(tmpString1)) { tmp = new Double(tmpString); tmp1 = new Double(tmpString1); } else { return "error"; } tmp = Math.pow(tmp1, tmp); tmpString2 = "" + tmp; flag1 = index + flag1 + 1; flag2 = index - flag2; if (0 == flag2) { tmpString = ""; } else { tmpString = string.substring(0, flag2); } if (string.length() == flag1) { tmpString1 = ""; } else { tmpString1 = string.substring(flag1, string.length()); } string = tmpString + tmpString2 + tmpString1; } else { tmpString = get_r_digit(string, index + flag); flag1 = tmpString.length(); if (!"error".equals(tmpString)) tmp = new Double(tmpString); else { return "error"; } tmpString2 = tmpString; if ("sin".equals(dispose)) { if ("error".equals(tmp)) return "error"; tmp = Math.sin(tmp); } else if ("cos".equals(dispose)) { if ("error".equals(tmp)) return "error"; tmp = Math.cos(tmp); } else if ("tan".equals(dispose)) { if ("error".equals(tmp)) return "error"; tmp = Math.tan(tmp); } else if ("log".equals(dispose)) { if ("error".equals(tmp)) return "error"; tmp = Math.log10(tmp); } else if ("ln".equals(dispose)) { if ("error".equals(tmp)) return "error"; tmp = Math.log(tmp); } else if ("√".equals(dispose)) { if ("error".equals(tmp)) return "error"; tmp = Math.sqrt(tmp); } else if ("log".equals(dispose)) { if ("error".equals(tmp)) return "error"; tmp = Math.log(tmp); } if (index != 0 && Character.isDigit(string.charAt(index - 1))) { tmpString = "×" + tmp; } else { tmpString = "" + tmp; } string = string.replaceFirst(dispose + tmpString2, tmpString); } } return string; } public String advanced_dispose(String string) { string = this.dispose1(string); string = this.bracke_dispose(string); string = this.alg_dispose(string); return string; } }
java類Judge程式碼:
package com.xueba.jsq; public class Judge { public String judge(String string, String c) { switch (string.charAt(string.length() - 1)) { case '+': case '-': case '×': case '÷': string = string.substring(0, string.length() - 1) + c; break; default: string += c; break; } return string; } public static String dispose(String string) { int leng = string.length() - 1; Character character; if (0 == leng) { return "error"; } for (int i = 0; i < leng; i++) { character = string.charAt(i); if (Character.isLetter(character)) { return "error"; } } return string; } public String judge1(String string) { int p = string.length() - 1; boolean flag = true; Character tmp = string.charAt(p); if (0 == p) string += "."; if (Character.isDigit(tmp) && 0 != p) { while (flag) { if (!Character.isDigit(tmp)) { flag = false; if (tmp != '.') string += "."; } if (0 == --p && (tmp != '.')) { string += "."; break; } tmp = string.charAt(p); } } return string; } public static boolean paiduan(Character c) { switch (c) { case '+': case '-': case '×': case '÷': return true; default: return false; } } public String digit_judge(String string, String c, boolean flag) { if ("0".equals(string)) { string = c; } else if (flag) { string = c; } else string += c; return string; } public String digit_dispose(String string) { if ("error".equals(string)) { return string; } Double double1 = new Double(string); if(double1>999999999999999.0) return "∞"; long l = (long) (double1 * 1e4); double1 = (Double) (l / 1e4); string = "" + double1; return string; } }
以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支援it145.com。
相關文章
<em>Mac</em>Book项目 2009年学校开始实施<em>Mac</em>Book项目,所有师生配备一本<em>Mac</em>Book,并同步更新了校园无线网络。学校每周进行电脑技术更新,每月发送技术支持资料,极大改变了教学及学习方式。因此2011
2021-06-01 09:32:01
综合看Anker超能充系列的性价比很高,并且与不仅和iPhone12/苹果<em>Mac</em>Book很配,而且适合多设备充电需求的日常使用或差旅场景,不管是安卓还是Switch同样也能用得上它,希望这次分享能给准备购入充电器的小伙伴们有所
2021-06-01 09:31:42
除了L4WUDU与吴亦凡已经多次共事,成为了明面上的厂牌成员,吴亦凡还曾带领20XXCLUB全队参加2020年的一场音乐节,这也是20XXCLUB首次全员合照,王嗣尧Turbo、陈彦希Regi、<em>Mac</em> Ova Seas、林渝植等人全部出场。然而让
2021-06-01 09:31:34
目前应用IPFS的机构:1 谷歌<em>浏览器</em>支持IPFS分布式协议 2 万维网 (历史档案博物馆)数据库 3 火狐<em>浏览器</em>支持 IPFS分布式协议 4 EOS 等数字货币数据存储 5 美国国会图书馆,历史资料永久保存在 IPFS 6 加
2021-06-01 09:31:24
开拓者的车机是兼容苹果和<em>安卓</em>,虽然我不怎么用,但确实兼顾了我家人的很多需求:副驾的门板还配有解锁开关,有的时候老婆开车,下车的时候偶尔会忘记解锁,我在副驾驶可以自己开门:第二排设计很好,不仅配置了一个很大的
2021-06-01 09:30:48
不仅是<em>安卓</em>手机,苹果手机的降价力度也是前所未有了,iPhone12也“跳水价”了,发布价是6799元,如今已经跌至5308元,降价幅度超过1400元,最新定价确认了。iPhone12是苹果首款5G手机,同时也是全球首款5nm芯片的智能机,它
2021-06-01 09:30:45