我有一個任務來處理複數。每個數字由雙r =實部,雙i =虛部和字符串名組成。名稱必須在構造函數中設置,所以我創建了int計數器,然後我將它的值發送到setNextName函數並返回名稱字母。不幸的是,增加這個'counter'值只能在costructor中運行,然後再次設置爲0.如何處理這個?一些常數值?第二個問題是我還需要提供setNextNames(char c)函數來改變計數器的當前值。會記住它的值的計數器
代碼:
public class Imaginary {
private double re;
private double im;
private String real;
private String imaginary;
private String name;
private int counter=0;
public Imaginary(double r, double u){
re = r;
im = u;
name = this.setNextName(counter);
counter++;
}
public static String setNextName(int c){
String nameTab[] = {"A","B","C","D","E","F","G","H","I","J","K","L","M","N",
"O","P","Q","R","S","T","U","W","V","X","Y","Z"};
String setName = nameTab[c];
System.out.println("c: "+c);
return setName;
}
public static String setNextName(char c){
//
//don't know how to deal with this part
//
}
我希望只有蟒蛇...... :)謝謝 – owca 2010-03-21 14:34:14
@owca:你爲什麼要生活在這樣一個有限的宇宙?!無論語言多麼優秀,我都不會只想要一種語言。或冰淇淋的味道。或音樂的風格。或者......或者......或者......-) – 2010-03-21 14:35:59
@TJC:好說:) – codaddict 2010-03-21 14:39:17