導航:首頁 > 編程語言 > 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乘號源碼相關的資料

熱點內容
文件掃描件製作軟體 瀏覽:419
一個女的變蛇了主角有一個女鬼叫北安 瀏覽:824
網路用語游戲開小灶什麼意思 瀏覽:413
免費追劇不卡的網站 瀏覽:921
視頻怎麼添加網站 瀏覽:797
威脅網路安全的典型案例有哪些 瀏覽:42
瀟湘溪苑師徒訓誡文嚴苛 瀏覽:641
劍靈武器大師幻彩石在哪個文件換 瀏覽:33
男同露骨電影 瀏覽:664
操作軟體映像文件如何下載 瀏覽:736
安卓logopsd 瀏覽:761
ipadmini2還原密碼 瀏覽:145
雲南精準扶貧大數據管理平台登陸 瀏覽:6
android支付微信介面開發 瀏覽:444
和女朋友一起看電影色色的電影 瀏覽:967
數控編程畢業可以干什麼 瀏覽:966
泰國永恆電影下載 瀏覽:306
大數據課程推薦 瀏覽:638
男主是吸血鬼的小說 瀏覽:192
玩網路游戲有什麼壞處 瀏覽:973

友情鏈接