import java.util.Scanner;
創(chuàng)新互聯(lián)公司是專業(yè)的來賓網(wǎng)站建設(shè)公司,來賓接單;提供成都網(wǎng)站制作、網(wǎng)站建設(shè),網(wǎng)頁設(shè)計(jì),網(wǎng)站設(shè)計(jì),建網(wǎng)站,PHP網(wǎng)站建設(shè)等專業(yè)做網(wǎng)站服務(wù);采用PHP框架,可快速的進(jìn)行來賓網(wǎng)站開發(fā)網(wǎng)頁制作和功能擴(kuò)展;專業(yè)做搜索引擎喜愛的網(wǎng)站,專業(yè)的做網(wǎng)站團(tuán)隊(duì),希望更多企業(yè)前來合作!
import java.util.Stack;
public class 表達(dá)式計(jì)算 {
private static StackString num = new StackString();//存后綴表達(dá)式
private static StackString sign = new StackString();//存入符號
private static StackInteger result = new StackInteger();//放結(jié)果
public static void getGroup(String line){//講字符串轉(zhuǎn)換為后綴表達(dá)式
for(int i=0; iline.length(); i++){
char c = line.charAt(i);
if((int)c=48 (int)c=57){//當(dāng)遇到數(shù)字的時(shí)候,判斷是不是多位數(shù),然后在push進(jìn)num
int j = i+1;
while(jline.length() (line.charAt(j)=48 line.charAt(j)=57)){
j++;
}
num.push(line.substring(i, j));
i = j-1;
}else if(c == '('){//遇到左括號直接存進(jìn)num
sign.push(String.valueOf(c));
}else if(c == ')'){//遇到右括號從sign中pop棧頂元素push到num知道遇到'(',然后再pop掉'('
while(!sign.peek().equals("(")){
num.push(sign.pop());
}
sign.pop();
}else{
int n = 0;
if(!sign.empty()){//如果sign中沒有元素,直接令n = 0
n = getNum(sign.peek().charAt(0));
}
int m = getNum(c);
if(m = n){//如果當(dāng)前元素的運(yùn)算級別比棧頂元素運(yùn)算級別要高,就直接push進(jìn)sign
sign.push(String.valueOf(c));
}else{
while(m n){//如果當(dāng)前運(yùn)算運(yùn)算級別比sign棧頂元素運(yùn)算級別要低,就將sign棧頂元素pop并且push進(jìn)num,知道不符合條件
num.push(sign.pop());//輸入例子2*3+6/3的時(shí)候,這里一直報(bào)錯(cuò)
if(!sign.empty()){
n = getNum(sign.peek().charAt(0));
}else{
n = 0;
}
}
sign.push(String.valueOf(c));
}
}
}
while(!sign.empty()){
num.push(sign.pop());
}
}
private static int getNum(char c){
int n = 0;
switch(c){
case '+':
case '-':
n = 1;
break;
case '*':
case '/':
n = 2;
break;
}
return n;
}
public class Tree {
private int treeId;
private String treeType;// 樹種類型
private int count; //種植數(shù)量
public int getCount() {
return count;
}
public void setCount(int count) {
this.count = count;
}
public int getTreeId() {
return treeId;
}
public void setTreeId(int treeId) {
this.treeId = treeId;
}
public String getTreeType() {
return treeType;
}
public void setTreeType(String treeType) {
this.treeType = treeType;
}
}
public class Address {
private int addCode;//地區(qū)編碼
private String area;//地名
public int getAddCode() {
return addCode;
}
public void setAddCode(int addCode) {
this.addCode = addCode;
}
public String getArea() {
return area;
}
public void setArea(String area) {
this.area = area;
}
}
import java.util.HashMap;
import java.util.Map;
public class People {
private int userId;
private String username;
private MapString,MapString,Integer map;
/**
* 傳入地區(qū)和樹種,種樹成功。保存到map中。
* @param address
* @param tree
*/
public void plantingTrees(String address,Tree tree){
Map map = new HashMap();
map.put(tree.getTreeType(),tree.getCount());
this.map.put(address,map);
}
public int getUserId() {
return userId;
}
public void setUserId(int userId) {
this.userId = userId;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public MapString, MapString, Integer getMap() {
return map;
}
public void setMap(MapString, MapString, Integer map) {
this.map = map;
}
}
源代碼是.java
一般項(xiàng)目里邊可以很多類型的文件如:
.jsp
.jar等。
按照你的要求加詳細(xì)注釋的圣誕樹Java程序如下:(編程思想在注釋中說明)
public?class?ShengDanShu2?{
//這個(gè)程序的編程思想是利用對for循環(huán)變量i的控制達(dá)到一層循環(huán)代替雙層循環(huán)的目的
public?static?void?main(String[]?args)?{????
int???n=5;???//初始化打印圣誕樹層數(shù)變量n
int???a=0;???//初始化打印前置空格數(shù)變量a
int???b=0;???//初始化打印星號數(shù)變量b
for(int?i=1;i?=n;i++){???//打印n層圣誕樹
if(a!=(n-i)){????//如果前置空格數(shù)不等于n-i
System.out.print("?");?//打印一個(gè)空格
a++;????//前置空格數(shù)加一???
i=i-1;????//i變量減一??目的是固定住i變量不變直到a==n-i
}else?if(b!=(2*i-1)){???//如果星號數(shù)不等于2*i-1
System.out.print("*");??//打印一個(gè)星號
b++;????//星號數(shù)加一
i=i-1;???//i變量減一??目的是固定住i變量不變直到b==2*i-1
}else?if(a==(n-i)??b==(2*i-1)){//當(dāng)以上兩個(gè)條件都滿足時(shí),換行初始化a和b為0???
System.out.println();??//打印換行?
a=0;???//對新的一行重新初始化前置空格數(shù)變量a
b=0;??//對新的一行重新初始化打印星號數(shù)變量b
//這里沒有控制for循環(huán)的i變量減一,因?yàn)檫@時(shí)i變量加一,開始新一行。
}???
}???
}?????
}
運(yùn)行結(jié)果:
*
***
*****
*******
*********