导航:首页 > 编程语言 > java乘号源码

java乘号源码

发布时间:2021-10-24 23:49:52

1. 求助java中如何在控制台输入乘号

✕ 是 (char) 10005
如果你不是指这个符号,可以用下面代码找到该符号的unicode(10进制)

char c = '✕';
System.out.println((int) c);

把c的值换成你需要的符号(比如从word里面生成之后复制过来)

2. 如何在java控制台上打印乘号不是* ,是日常生活中的。

✕ 是 (char) 10005
如果你不是指这个符号,可以用下面代码找到该符号的unicode(10进制)

char c = '✕';
System.out.println((int) c);

把c的值换成你需要的符号(比如从word里面生成之后复制过来)

3. 用java编写乘号菱形金字塔的程序

根据下面代码自己修改吧,这肯定是你想要的

public static void main(String[] args) {
int i, j, k;
for (i = 1; i <= 3; i++) {
for (j = 1; j <= 3 - i; j++)
System.out.print(" ");
for (k = 1; k <= 2 * i - 1; k++)
System.out.print("*");
System.out.println("");
}
for (i = 1; i <= 2; i++) {
for (j = 1; j <= i; j++)
System.out.print(" ");
for (k = 1; k <= 5 - 2 * i; k++)
System.out.print("*");
System.out.println("");
}
}

4. 要求一个简单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 Calculator 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) {
Calculator frm = new Calculator();
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";

}
}

}

5. 关于java做的计算器源代码

关于计算器的设计其实是一个很大的学问,如果你按照严格的设计来完成一个计算器的话,完成之后。你就是一个很牛的人了。注意我说的是很牛
关于这方面的资料我建议你看本书
《大话设计模式》
这本书就是从计算器来展开的设计模式的运用和讲解

6. java 写的计算器源代码只实现加减乘除四则运算即可

import java.awt.*; //引入AWT包
import java.awt.event.*; //引入awt.event包
import javax.swing.*; //引入javax.swing包
public class JSQ extends JFrame implements ActionListener //事件监听器为接口
{
private String name[] =
{"0","1", "2","+","3","4","5","-","6","7","8","*","9",".","=","/"}; //创建按钮数组
private String extend[] =
{"x^2","ln","back","sin","cos","tan","sqrt","关闭","清空"}; String s="";
int flag=0;
double x;
final double pi = 3.14159265358979323846;
private JButton button[] = new JButton[name.length]; //创建按钮数组

private JButton button1[] = new JButton[extend.length]; //创建功能键按钮数组

JLabel dis_show = new JLabel("结果:");
JTextField w = new JTextField(12); //文本长度为12
public JSQ2() //构造函数
{
super("计算机");
setSize(200,290);
Container c = getContentPane();
c.setLayout(new GridLayout(2,1,0,0));
JPanel result = new JPanel();
result.add(dis_show);
result.add(w);
for(int i= 0;i<extend.length;i++) //循环
{
button1[i] = new JButton(extend[i]);
result.add(button1[i]);
}
JPanel border = new JPanel();
for(int i= 0;i<name.length;i++)
{
button[i] = new JButton(name[i]);
border.add(button[i]);
}
c.add(result);
c.add(border);
for(int i= 0;i<name.length;i++)
{
button[i].addActionListener(this);
}
for(int i= 0;i<extend.length;i++)
{
button1[i].addActionListener(this);
}
show();
}
public void actionPerformed(ActionEvent e)
{
if (e.getSource()==button[3])
{
x=Double.parseDouble(s);

flag=1;
w.setText("");
s="";
}
else if (e.getSource()==button[7])
{
x=Double.parseDouble(s);
flag=2;
w.setText("");
s="";
}
else if (e.getSource()==button[11])
{
x=Double.parseDouble(s);
flag=3;
w.setText("");
s="";
}
else if (e.getSource()==button[15])
{
x=Double.parseDouble(s);
flag=4;
w.setText("");
s="";
}
else if (e.getSource()==button[14])
{
switch(flag)
{
case 1:
{

x=x+Double.parseDouble(s);
String s=String.valueOf(x);
w.setText(s);
break;
}
case 2:
{
x=x-Double.parseDouble(s);
String s=String.valueOf(x);
w.setText(s);
break;
}
case 3:
{
x=x*Double.parseDouble(s);
String s=Double.toString(x);
w.setText(s);
break;
}
case 4:
{
if(Double.parseDouble(s)==0)
{
w.setText("除数不能为0");
break;
}
x=x/Double.parseDouble(s);
String s=String.valueOf(x);
w.setText(s);
break;
}
}
}
else if(e.getSource()==button1[2])
{
StringBuffer str = new StringBuffer(w.getText());
int n=str.length();
int m=n-1;
s = String.valueOf(str.delete(m,n));
w.setText(s);
}
else if(e.getSource()==button1[8])
{
w.setText("");
s="";
flag=0;
}
else if(e.getSource()==button1[0])
{
x=Double.parseDouble(s);
x=x*x;
String s=String.valueOf(x);
w.setText(s);
}
else if(e.getSource()==button1[1])
{
x=Math.log(Double.parseDouble(s));
String s=String.valueOf(x);
w.setText(s);
}
else if(e.getSource()==button1[3])
{
x=Math.sin(Double.parseDouble(s)*pi/180);
String s=String.valueOf(x);
w.setText(s);
}
else if(e.getSource()==button1[6])
{
x=Math.sqrt(Double.parseDouble(s));
String s=String.valueOf(x);
w.setText(s);
}
else if(e.getSource()==button1[4])
{
x=Math.cos(Double.parseDouble(s)*pi/180);
String s=String.valueOf(x);
w.setText(s);
}
else if(e.getSource()==button1[5])
{
x=Math.tan(Double.parseDouble(s)*pi/180);
String s=String.valueOf(x);
w.setText(s);
}
else if(e.getSource()==button1[7])
{
System.exit(0);
}
else
{
s=s+e.getActionCommand();
w.setText(s);
}
}
public static void main(String[] args)
{
JSQ2 bun = new JSQ();
bun.addWindowListener(new WindowAdapter()
{
public void windowListener(WindowEvent e)
{
System.exit(0);
}
});
}
}
太多啦,懒得解释啦!总的来说就是先创建数组按钮,然后放入面板,面板再加入FRAME,然后实现监听器的方法(按钮功能)!其中要用到布局管理器,具体查看API!

7. 用JAVA语言在网页里实现加减乘除算法的源代码要怎么写吖!

如果要用java语言在网页实现的话:
那网页必须是JSP
<%
java code
%>
这样就ok了

8. java里的乘号怎么写,result1=("i1/i2"*5) ; /*想让i1/i2的结果乘以5怎么写*/

result1=i1/i2*5;

9. java源代码中各符号意义

深圳远标(ITJOB)帮你:
Java代码规范之一 ——标识符命名规范

转载 2015-08-19 12:06:22

1. 标识符命名规范

1.1 概述

标识符的命名力求做到统一、达意和简洁。

1.1.1

统一

统一是指,对于同一个概念,在程序中用同一种表示方法,比如对于供应商,既可以用supplier,也可以用provider,但是我们只能选定一个使用,至少在一个Java项目中保持统一。统一是作为重要的,如果对同一概念有不同的表示方法,会使代码混乱难以理解。即使不能取得好的名称,但是只要统一,阅读起来也不会太困难,因为阅读者只要理解一次。

1.1.2

达意

达意是指,标识符能准确的表达出它所代表的意义,比如: newSupplier,
OrderPaymentGatewayService等;而 supplier1,
service2,idtts等则不是好的命名方式。准确有两成含义,一是正确,而是丰富。如果给一个代表供应商的变量起名是
order,显然没有正确表达。同样的,supplier1, 远没有targetSupplier意义丰富。

1.1.3

简洁

简洁是指,在统一和达意的前提下,用尽量少的标识符。如果不能达意,宁愿不要简洁。比如: 太长,
则较好,但是transTgtSplOrdNm就不好了。省略元音的缩写方式不要使用,我们的英语往往还没有好到看得懂奇怪的缩写。

1.1.4

骆驼法则

Java中,除了包名,静态常量等特殊情况,大部分情况下标识符使用骆驼法则,即单词之间不使用特殊符号分割,而是通过首字母大写来分割。比如:
SupplierName, addNewContract,而不是 supplier_name,
add_new_contract。

10. JAVA中*(乘号问题)

既然直接得不到 * 你就用其他方法来获取符号,
如果是为了实现一个算式,
可以这样,
参数用一个字符串表示 "2*3" 或者 * 前面没有分隔符
import java.util.*;

public class chenghao {
public static void main(String[] args) {
String input = args[0]+" ";
String num = "";
List<String> aa = new LinkedList<String>();
for (int i = 0; i < input.length(); i++) {
if ('0' <= input.charAt(i)
&& input.charAt(i) <= '9') {
num += input.charAt(i);
} else {
aa.add(num);
aa.add(input.charAt(i)+"");
num = "";
}
}
Iterator<String> it = aa.iterator();
while(it.hasNext()){
System.out.println(it.next());
}

}
}

阅读全文

与java乘号源码相关的资料

热点内容
linux用户读写权限 浏览:936
少侠十七妻全文阅读 浏览:422
公主奴 浏览:856
k9d3 浏览:182
分卷阅读 玩武警少尉 浏览:44
知乎写小说入口 浏览:772
美国农场爱情片 浏览:709
主角一开始就长生不老 浏览:338
mike文件内容和输入不匹配 浏览:499
plsql怎么连接数据库连接 浏览:951
大黄文 浏览:213
刀剑神域小说TXT 浏览:369
电影《夏宫》 浏览:213
ps怎么打不开psd文件格式 浏览:805
wode办公文件格式 浏览:264
怎么备份oracle数据库备份 浏览:69
校草和系草txt下载 浏览:124
穿越成纣王斩神的小说 浏览:708
锦衣卫 下载 浏览:500
徐元的电影中文字 浏览:841

友情链接