Zum Inhalt springen
View in the app

A better way to browse. Learn more.

Fachinformatiker.de

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

array reversion, klappt nicht *totaler anfänger*

Empfohlene Antworten

Veröffentlicht

Halli hallo,

möchte gerne eine reversion eines arrays ausgeben lassen ( {a, b, c, d} => {d, c, b, a,} ) , bekomm jedoch nur fehler und verlier den überblick


class Reversion {

public static void main ( String[] args ) {

/* Deklarationen und Intialisierungen */

char[] c = {’a’, ’b’, ’c’, ’d’}; 



System.out.println(c[0] + " " + c[1] + " " + c[2] + " " + c[3]);


char[] tmp = new char[c.length];

for (int n=c.length-1; n>=0; n--) {

tmp[(c.length-1) - n] = c[n];

}

c = tmp;

/* Ausgabe der Reversion */

System.out.println(c[0] + " " + c[1] + " " + c[2] + " " + c[3]);

}

}

bitte kann das mal jemand druchjagen und meine fehler aufdecken ? Fehlercode

C:\Users\Administrator\Documents\NetBeansProjects\MarsRoverViewer\src\NewClass11.java:16: illegal start of type

System.out.println(c[0] + " " + c[1] + " " + c[2] + " " + c[3]);

C:\Users\Administrator\Documents\NetBeansProjects\MarsRoverViewer\src\NewClass11.java:16: <identifier> expected

System.out.println(c[0] + " " + c[1] + " " + c[2] + " " + c[3]);

C:\Users\Administrator\Documents\NetBeansProjects\MarsRoverViewer\src\NewClass11.java:16: ';' expected

System.out.println(c[0] + " " + c[1] + " " + c[2] + " " + c[3]);

91 errors

vielen dank für eure hilfe und aufmerksamkeit :(

mfg jay

Bei mir funktioniert dein Code fehlerfrei.

Das einzige was ich ändern musste war die initalisierung des char-Array c.

char[] c = { 'a', 'b', 'c', 'd' };
und NICHT:
char[] c = {’a’, ’b’, ’c’, ’d’};
Ausgabe am Ende bei mir:
a b c d

d c b a

danke danke danke ;)

hab den wald vor lauter bäumen nicht gesehen und mich gefragt was der schon wieder für ******* anführungszeichen brauch :P

:upps

Archiv

Dieses Thema wurde archiviert und kann nicht mehr beantwortet werden.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.