1.4 Einführung Java verwenden von Variablen / Einführung Java verwenden von Variablen

1.4 Einführung Java verwenden von Variablen / Einführung Java verwenden von Variablen


Jetzt schauen wir uns mal an wie man die verschiedenen Variablen ausgeben kann:

 

public class halloVariablen {

       public static void main (String[] args) {

               String name = "Jana";

               int alter = 27;

               double groesse = 1.55;

               System.out.println("Mein Name ist " + name + " ich bin " + alter + " Jahre alt" + " und bin " + groesse + " m gross ");

       }

}

Das währe nun unsere Ausgabe:

351665157-baac8481f295beca56745dee4f5d8aea5226e6721abe17ac00a785ae1d2a8854.png

English:

Now let's take a look at how to output the different variables:

 


public class helloVariables {

public static void main (String[] args) {

String name = "Jana";

int alter = 27;

double size = 1.55;

System.out.println("My name is " + name + " I am " + old + " years old" + " and am " + size + " m size ");

}

}

That would be our issue now: My name is Jana i´m 27 Jears old and im 1.55 m tall

 

 

Wir können auch mit Variablen rechnen hierzu mal ein Kleines Beispiel:

public class halloVariablen {

       public static void main (String[] args) {

               int wert1 = 6;

               int wert2 = 7;

               double wert3 = 3.8;              

 

               int ergebnis = wert1 * wert2 + (int)wert3; //Wenn wir so rechnen wollen müssen wir schauen das die Datentypen gleich sind.

                                                                             //Wollen wir einen double Datentypen müssen wir den double Typ zu int casten.

                                                                             // Das machen wir indem wir vor der double variable in Klammern int schreiben.

                                                                            //In diesem fall wird beim casten einfach die Nachkommastelle nicht beachtet.

               System.out.println("Das Ergebnis ist: " + ergebnis);

       }

}

351665157-f04c2423dbf54ae377831ed6024f01682ad63c30e8e951dff9ce72a11ff88aa8.png

 

English:

We can also calculate with variables for this a small example:

public class helloVariables {

public static void main (String[] args) {

int value1 = 6;

int value2 = 7;

double value3 = 3.8;

 


int result = value1 * value2 + (int)value3; //If we want to calculate like this we have to make sure that the datatypes are the same.

//If we want a double datatype we have to cast the double type to int.

// We do this by putting int in brackets in front of the double variable.

// In this case the decimal place is ignored when casting.

System.out.println("The result is: " + result);

}

}

The result is : 45

 

Wenn wir aber wollen das die Nachkommastellen beachtet werden dann muss die Variable ergebnis ein double sein.

double ergebnis = wert1 * wert2 * wert3;

351665157-f6d74d82169a77c0eff77e87021bef1497406975c8382dbc3883dec5231d150b.png

 

English:

 

But if we want the decimal places to be considered then the variable result must be a double.

double result = value1 * value2 * value3;

 

The rsult is: 159.6

How do you rate this article?

0


Conschdi
Conschdi

Im a human. https://bittubers.com/profile/Beautiful-World Peace & Love to everyone.


App entwicklung mit Android Studio in Java
App entwicklung mit Android Studio in Java

In diesem Blog erkläre ich schritt für schritt wie man eigene Apps mit Android Studio in der Programmiersprache Java eigenhändig programmiert. In this blog I explain step by step how to program your own apps with Android Studio in the programming language Java.

Publish0x

Send a $0.01 microtip in crypto to the author, and earn yourself as you read!

20% to author / 80% to me.
We pay the tips from our rewards pool.