class Arithmetic public static void mainString args int
Εκτέλεση απλών αριθμητικών πράξεων. Ένα πρώτο απλό παράδειγμα με ακέραιους αριθμούς: class Arithmetic { public static void main(String args[ ]) { int x = 17, y = 5; System. out. println("x = " + x); System. out. println("y = " + y); System. out. println("x + y = " + (x + y)); System. out. println("x - y = " + (x - y)); System. out. println("x * y = " + (x * y)); System. out. println("x / y = " + (x / y)); System. out. println("x % y = " + (x % y)); } } Τετάρτη, 22 Δεκεμβρίου 2021 Γεωργιάδης Ζαφείρης
Πράξεις με boolean – τελεστές class Relational { public static void main(String args[]) { int x = 7, y = 11, z = 11; System. out. println("x = " + x); System. out. println("y = " + y); System. out. println("x < y = " + (x < y)); System. out. println("x > z = " + (x > z)); System. out. println("y <= z = " + (y <= z)); System. out. println("x >= y = " + (x >= y)); System. out. println("y == z = " + (y == z)); System. out. println("x != z = " + (x != z)); } Τετάρτη, 22 Δεκεμβρίου 2021 Γεωργιάδης Ζαφείρης }
Παράδειγμα χρήσης της if – else if class If Else { public static void main(String args[]) { int month = 4; // April String season; if (month == 12 || month == 1 || month == 2) season = "Winter"; else if (month == 3 || month == 4 || month == 5) season = "Spring"; else if (month == 6 || month == 7 || month == 8) season = "Summer"; else if (month == 9 || month == 10 || month == 11) season = "Autumn"; else season = "Error in Month"; System. out. println("April is in the " + season + ". "); } } Τετάρτη, 22 Δεκεμβρίου 2021 Γεωργιάδης Ζαφείρης
class Demo. While { public static void main(String args[]) { int i = 10; while(i > 0) { System. out. println("Number : " + i); i--; } } } Τετάρτη, 22 Δεκεμβρίου 2021 Γεωργιάδης Ζαφείρης
class Do. While { public static void main(String args[]) { int i = 10; do { System. out. println("Number : " + i); i--; } while(i > 0); } } Τετάρτη, 22 Δεκεμβρίου 2021 Γεωργιάδης Ζαφείρης
- Slides: 17