Hallo,
bei meinem Programm soll zu Anfang ausgewählt werden ob multipliziert, addiert, subtrahiert oder multipliziert wird. Danach werden die Zahlen eingelesen und dann sollte das Ergebnis eigentlich in der Console ausgeben werden, tut es aber nicht..
Hier mein Quellcode:
[Java]
import java.io.*;
public class berechnen {
/**
*
* @param args
*/
public static void main(String[] args)
{
int a, b = 0 ;
String s = null;
System.out.println("Geben Sie die erste Zahl ein...");
a = readInt();
System.out.println("Geben Sie die zweite Zahl ein...");
b = readInt();
System.out.println("Wählen Sie mu, add, sub, div");
s = readString(); // auswählen der verschiedenen Berechnungsarten
if (s == "mu") {
System.out.println(berechnen.mal(a, b));
}
if (s == "sub") {
System.out.println( berechnen.sub(a, b) );
}
if (s == "add") {
System.out.println(berechnen.add(a, b)) ;
}
if (s == "div") {
System.out.println(berechnen.div(a, b));
}
}
public static int readInt () {
return Integer.valueOf(readString()).intValue();
}
public static String readString() // Einlesen eines Strings
{
try {
BufferedReader in = new BufferedReader(
new InputStreamReader(System.in) );
String s = in.readLine();
return s;
}
catch (IOException ex ) {
System.out.println( ex.getMessage());
}
return "Keine Eingabe";
}
public static int mal(int zahl1, int zahl2)
{
int x = zahl1;
int y = zahl2;
int result = y * x ;
return result;
}
public static int add(int zahl1, int zahl2)
{
int x = zahl1;
int y = zahl2;
int result = y + x ;
return result;
}
public static int sub(int zahl1, int zahl2)
{
int x = zahl1;
int y = zahl2;
int result = y - x ;
return result;
}
public static int div(int zahl1, int zahl2)
{
int x = zahl1;
int y = zahl2;
int result = y/x ;
return result;
}
}
[/Java]
bei meinem Programm soll zu Anfang ausgewählt werden ob multipliziert, addiert, subtrahiert oder multipliziert wird. Danach werden die Zahlen eingelesen und dann sollte das Ergebnis eigentlich in der Console ausgeben werden, tut es aber nicht..
Hier mein Quellcode:
[Java]
import java.io.*;
public class berechnen {
/**
*
* @param args
*/
public static void main(String[] args)
{
int a, b = 0 ;
String s = null;
System.out.println("Geben Sie die erste Zahl ein...");
a = readInt();
System.out.println("Geben Sie die zweite Zahl ein...");
b = readInt();
System.out.println("Wählen Sie mu, add, sub, div");
s = readString(); // auswählen der verschiedenen Berechnungsarten
if (s == "mu") {
System.out.println(berechnen.mal(a, b));
}
if (s == "sub") {
System.out.println( berechnen.sub(a, b) );
}
if (s == "add") {
System.out.println(berechnen.add(a, b)) ;
}
if (s == "div") {
System.out.println(berechnen.div(a, b));
}
}
public static int readInt () {
return Integer.valueOf(readString()).intValue();
}
public static String readString() // Einlesen eines Strings
{
try {
BufferedReader in = new BufferedReader(
new InputStreamReader(System.in) );
String s = in.readLine();
return s;
}
catch (IOException ex ) {
System.out.println( ex.getMessage());
}
return "Keine Eingabe";
}
public static int mal(int zahl1, int zahl2)
{
int x = zahl1;
int y = zahl2;
int result = y * x ;
return result;
}
public static int add(int zahl1, int zahl2)
{
int x = zahl1;
int y = zahl2;
int result = y + x ;
return result;
}
public static int sub(int zahl1, int zahl2)
{
int x = zahl1;
int y = zahl2;
int result = y - x ;
return result;
}
public static int div(int zahl1, int zahl2)
{
int x = zahl1;
int y = zahl2;
int result = y/x ;
return result;
}
}
[/Java]