[Java] Fehler in "public class Methode"

Dieses Thema im Forum "Programmierung & Entwicklung" wurde erstellt von Webwatcher, 28. Oktober 2009 .

  1. 28. Oktober 2009
    Fehler in "public class Methode"

    Hallo,
    habe gerade in der Vorlesung das Thema Methoden. Ich poste hier mal mein Programm, vllt kann mir jemand bei der Fehlersuche helfen, es läuft nocht nicht wie es sollte.
    Soll ein Taschenrechner werden, mit + - * /:


    public class Methoden {
    // Methoden ohne Rückgabe
    public static void addieren(int x, int y) {
    System.out.printlnx + y;
    }

    public static void subtrahieren(int x, int y) {
    System.out.println(x - y);
    }

    public static void multiplizieren(int x, int y) {
    System.out.println(x * y);
    }

    public static void dividieren int x, int y) {
    System.out.println(x / y);
    }

    // ////////////////////////////////////////////////////////////////////

    // Methoden mit Rückgabe

    public static int addieren2(int x, int y) {

    return x + y;
    }

    public static int subtrahieren2(int x, int y) {

    return x - y;
    }

    public static int multiplizieren2(int x, int y) {

    return x * y;
    }

    public static int dividieren2(int x, int y) {

    return x / y
    }

    public static void main(String[] args) {

    System.out.println("Ohne Rückgabewert");
    addieren(10, 2);
    subtrahieren(10, 2);
    multiplizieren(10, 2);
    dividieren(10, 2);

    // ///////////////////////////////////////////////////////////////////////////

    System.out.println();
    System.out.println("Mit Rückgabewert");

    System.out.println(addieren2(10, 2));
    System.out.println(subtrahieren2(10, 2));
    System.out.println(multiplizieren2(10, 2));
    System.out.println(dividieren2(10, 2));

    }

    }
     
  2. 28. Oktober 2009
    AW: Fehler im Programm

    bitte sehr, waren nur 3 syntax-fehler.
    habe sie als kommentar im code markiert.

    Code:
    public class Methoden {
     // Methoden ohne Rückgabe
     public static void addieren(int x, int y) {
     System.out.println(x + y); //<--Klammern vergessen
     }
    
     public static void subtrahieren(int x, int y) {
     System.out.println(x - y);
     }
    
     public static void multiplizieren(int x, int y) {
     System.out.println(x * y);
     }
    
     public static void dividieren(int x, int y) { //<--Klammer vergessen
     System.out.println(x / y);
     }
    
     // ////////////////////////////////////////////////////////////////////
    
     // Methoden mit Rückgabe
    
     public static int addieren2(int x, int y) {
    
     return x + y;
     }
    
     public static int subtrahieren2(int x, int y) {
    
     return x - y;
     }
    
     public static int multiplizieren2(int x, int y) {
    
     return x * y;
     }
    
     public static int dividieren2(int x, int y) {
    
     return x / y; //<--Semikolon vergessen
     }
    
     public static void main(String[] args) {
    
     System.out.println("Ohne Rückgabewert");
     addieren(10, 2);
     subtrahieren(10, 2);
     multiplizieren(10, 2);
     dividieren(10, 2);
    
     // ///////////////////////////////////////////////////////////////////////////
    
     System.out.println();
     System.out.println("Mit Rückgabewert");
    
     System.out.println(addieren2(10, 2));
     System.out.println(subtrahieren2(10, 2));
     System.out.println(multiplizieren2(10, 2));
     System.out.println(dividieren2(10, 2));
     }
    }
    
    
     
  3. 28. Oktober 2009
    AW: Fehler im Programm

    Vielen Dank für die superschnelle Hilfe...
    Sooo jetzt kann ich das Programm endlich nutzen
     
  4. 28. Oktober 2009
    AW: Fehler im Programm

    kann ich hier noch eine Tastatureingabe hinzufügen? Also das die Zahlen über Tastatur eingelesen werden.
    wie würde das dann gehen???
     
  5. 28. Oktober 2009
    AW: Fehler in "public class Methode"

    Mach dir doch gleich ne kleine Oberfläche, mit 2 Textfeldern in die du deine 2 Zahlen eingeben kannst und paar Buttons, die dann je nach Klick eine der Methoden ausführen und ausgeben!

    Ansonsten müsstest du mit nem BufferedReader arbeiten:
    Java I/O
     
  6. 28. Oktober 2009
    AW: Fehler in "public class Methode"

    danke, bufferedreader war das was ich gesucht habe, mir ist das wort nicht mehr eingefallen :]
     
  7. Video Script

    Videos zum Themenbereich

    * gefundene Videos auf YouTube, anhand der Überschrift.