/ Forside / Teknologi / Udvikling / Java / Nyhedsindlæg
Login
Glemt dit kodeord?
Brugernavn

Kodeord


Reklame
Top 10 brugere
Java
#NavnPoint
molokyle 3688
Klaudi 855
strarup 740
Forvirret 660
gøgeungen 500
Teil 373
Stouenberg 360
vnc 360
pmbruun 341
10  mccracken 320
Baah... Hvorfor virker det her ikke ? arra~
Fra : rofe@mailme.dk


Dato : 05-10-02 21:51

public class Month
{
private int monthNr; /* the month number given by the user */
private String months[] = new String[12]; /* the month array */

/* the months */
months[0] = "Januar";
months[1] = "Februar";
months[2] = "Marts";
months[3] = "April";
months[4] = "Maj";
months[5] = "Juni";
months[6] = "Juli";
months[7] = "August";
months[8] = "September";
months[9] = "Oktober";
months[10] = "November";
months[11] = "December";

public Month(int monthNr)
{
this.monthNr = monthNr;
}

public String getName()
{
return months[monthNr - 1];
}
}



m v h
Ronni
rofe@mailme.dk





 
 
Mikkel Bundgaard (05-10-2002)
Kommentar
Fra : Mikkel Bundgaard


Dato : 05-10-02 22:08

On Sat, 05 Oct 2002 22:51:00 +0200, rofe wrote:

> public class Month
> {
> private int monthNr; /* the month number given by the user */
> private String months[] = new String[12]; /* the month array */
>
> /* the months */
> months[0] = "Januar";
> months[1] = "Februar";
> months[2] = "Marts";
> months[3] = "April";
> months[4] = "Maj";
> months[5] = "Juni";
> months[6] = "Juli";
> months[7] = "August";
> months[8] = "September";
> months[9] = "Oktober";
> months[10] = "November";
> months[11] = "December";
>
> public Month(int monthNr)
> {
> this.monthNr = monthNr;
> }
>
> public String getName()
> {
> return months[monthNr - 1];
> }
> }
>
> m v h
> Ronni
> rofe@mailme.dk
Hej Ronni

Du kan enten flytte din tildelinger (months[0]=..months[11]=) ned i din
konstruktør eller sætte {} omkring. Dvs.
/* the months */
{
months[0] = "Januar";
months[1] = "Februar";
....
months[11] = "December";
}

Håber du kan bruge det til noget
--
Mikkel Bundgaard
Student at IT University of Copenhagen
http://officehelp.gone.dk
Codito, Ergo Sum

Casper Lund Thomsen (05-10-2002)
Kommentar
Fra : Casper Lund Thomsen


Dato : 05-10-02 22:09

rofe@mailme.dk wrote:
> public class Month
> {
> private int monthNr; /* the month number given by the user */
> private String months[] = new String[12]; /* the month array */
>
> /* the months */
> months[0] = "Januar";
> months[1] = "Februar";
> months[2] = "Marts";
> months[3] = "April";
> months[4] = "Maj";
> months[5] = "Juni";
> months[6] = "Juli";
> months[7] = "August";
> months[8] = "September";
> months[9] = "Oktober";
> months[10] = "November";
> months[11] = "December";
>
> public Month(int monthNr)
> {
> this.monthNr = monthNr;
> }
>
> public String getName()
> {
> return months[monthNr - 1];
> }
> }

Hvad er mere præcist dit problem?

Mvh
Casper


Bertel Lund Hansen (05-10-2002)
Kommentar
Fra : Bertel Lund Hansen


Dato : 05-10-02 22:21

<rofe@mailme.dk> skrev:

>public class Month

Det er nemmere at gøre sådan her. Så er du også fri for at tælle:

class Month {
   private int monthNr;
   private String months[] = {
      "Januar", "Februar", "Marts",
      "April","Maj","Juni",
      "Juli", "August", "September",
      "Oktober", "November", "December" };

   public Month(int monthNr) { this.monthNr = monthNr; }

   public String getName() { return months[monthNr-1]; }

}

class Test {
   public static void main (String augh[]) {
      Month info = new Month(10);
      System.out.println(info.getName());
   }
}

--
Bertel
http://bertel.lundhansen.dk/   FIDUSO: http://fiduso.dk/

rofe@mailme.dk (05-10-2002)
Kommentar
Fra : rofe@mailme.dk


Dato : 05-10-02 22:36

Mange TAK !

Det virkede med
private String months[] = {
"Januar", "Februar", "Marts",
"April","Maj","Juni",
"Juli", "August", "September",
"Oktober", "November", "December" };


m v h
Ronni
rofe@mailme.dk



Søg
Reklame
Statistik
Spørgsmål : 177500
Tips : 31968
Nyheder : 719565
Indlæg : 6408518
Brugere : 218887

Månedens bedste
Årets bedste
Sidste års bedste