if (s.charAt(j) != '0')
{
isDec = false;
break;
}
if (isDec == true)
{
String stemp = "";
for (k = 0; ki; k++)
stemp += s.charAt(k);
text.setText(stemp);
}
else
text.setText(s);
}
clear=false;
}
if(temp==qiuyi)
{
text.setText("0");
clear=false;
}
if (temp == fu)
{ //导师,此方法参考书中例子
boolean isNumber = true;
String s = text.getText();
for (int i = 0; is.length(); i++)
if (! (s.charAt(i) = '0's.charAt(i) = '9' || s.charAt(i) == '.' ||
s.charAt(i) == '-'))
{
isNumber = false;
break;
}
if (isNumber == true)
{
//如果当前字符串首字母有'-'号,代表现在是个负数,再按下时,则将首符号去掉
if (s.charAt(0) == '-')
{
text.setText("");
for (int i = 1; is.length(); i++)
{
char a = s.charAt(i);
text.setText(text.getText() + a);
}
}
//如果当前字符串第一个字符不是符号,则添加一个符号在首字母处
else
text.setText('-' + s);
}
}
}
catch(Exception eee)
{
System.out.println("运算时,首先输入数字或字符");
text.setText("运算出错");
clear=false;
}
}
class WindowDestroyer extends WindowAdapter
{//退出窗口动作
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
}
class objConversion
{//导师,本进制类参考了CSMD类转换例子
public void objConversion ()
{
}
public String decDec (int decNum)
{//10
String strDecNum = Integer.toString(decNum);
for (int i = strDecNum.length(); i3; i++)
{
strDecNum = "0" + strDecNum;
}
// return strDecNum;
return invert (strDecNum, 5);
}
public String decHex (int decNum)
{//10 to 16
String strHexNum = "";
int currentNum = 0;
while (decNum != 0)
{
if (decNum15)
{
currentNum = decNum % 16;
decNum /= 16;
}
else
{
currentNum = decNum;
decNum = 0;
}
switch (currentNum)
{
case 15: strHexNum += "F";
break;
case 14: strHexNum += "E";
break;
case 13: strHexNum += "D";
break;
case 12: strHexNum += "C";
break;
case 11: strHexNum += "B";
break;
case 10: strHexNum += "A";
break;
default: strHexNum += Integer.toString(currentNum);
break;
}
}
return invert (strHexNum, 2);
}
public String decOct (int decNum)
{//10 to 8
String strOctNum = "";
while (decNum != 0)
{
if (decNum7)
{
strOctNum += Integer.toString(decNum % 8);
decNum /= 8;
}
else
{
strOctNum += Integer.toString(decNum);
decNum = 0;
}
}
return invert (strOctNum, 3);
}
public String decBin (int decNum)
{//10 to 2
String strBinNum = "";
while (decNum != 0)
{
if (decNum1)
{
strBinNum += Integer.toString(decNum % 2);
decNum /= 2;
}
else
{
strBinNum += Integer.toString(decNum);
decNum = 0;
}
}
return invert (strBinNum, 8);
}
private String invert (String strNum, int minLength) //转换长度
{
String answer = "";
int length = strNum.length();
if (lengthminLength)
{
for (int padding = (minLength - length); padding0; padding--)
{
answer += "0";
}
}
for (int i = length; i0; i--)
{
answer += strNum.charAt (i - 1);
}
return answer;
}
}
public static void main(String arg[])//产生窗口
{
calculator win = new calculator();
推荐阅读
- 解谜汉化版游戏,解谜游戏中文网
- chatgpt服务外包,服务外包 mp4
- 怎么下载手机版兽人游戏,手机兽人游戏有哪些
- 如何成为营销平台,如何成为营销平台经理
- linux命令行没了 linux怎么调出命令
- gis小镇软件的使用感受,arcgis小程序
- asp.net动态新闻,asp动态网页设计基于sql server 2005
- 食品直播回顾文案,食品直播开场白
- mysql不运行怎么办 mysql也不停止运行但是用不了