Declaration and Initialization of Variables:
JAVA: Variables are declared in Java by first
specifying the data type and then the variable
name. Initialization can take place in the code at
a later stage or upon declaration. Here's one
instance:
{java}int age; // initialize the variable, age =
25; // variable declaration
C#: Just with Java, variables in C# must be
declared with a specific data type before the
variable name. Initialization can take place in the
code at a later stage or upon declaration. Here's
one instance:
{csharp int age; // initialize the variable by
declaring it to be 25.
PYTHON: Variables in Python don't require
explicit data type declarations because they are
dynamically typed. During declaration, a variable
can have a value immediately assigned to it.
Here's one instance:
{python age = 25 # declaration and initialization
of variables}
PHP: PHP has dynamic type capabilities, just like
Python. Variables can be independently declared
and initialized or in a single line. Here's one
alternately:
print("This isn't an adult,")
Results of ternary-like expression: "Adult" if age
>= 18; otherwise, "Not an adult"
// While loop (i < 5) int i = 0; while
"System.out.println(i);" i++;
// While loop with int i = 0; do
{System.out.println(i); i++;} while (i < 5);}
C#: C# also has support for while, do-while, and
for loops.
{csharp}// For loop for (int i = 0; i < 5; i++)}−
Console.WriteLine(i);
// While loop // Console.WriteLine(i); i++; while
(i < 5)
// While loop while (i < 5) int i = 0;
Console.WriteLine(i); i++;
// While loop with int i = 0; do
{Console.WriteLine(i); i++;} while (i < 5); {
Phrase:
echoe $i, $i++, }
// Features akin to while
$i = 0; perform the operation {echo $i; $i++;}
while ($i < 5);
Features/Actions:
Java: Functions are defined inside classes and are
referred to as methods. This is an illustration of
how to declare and use a method:
The Java public class MyClass has the following
public static void main(String[] args): int sum =
addNumbers(5, 10); System.out.println("Sum: " +
sum);}
Return a + b from public static int
addNumbers(int a, int b);
C#: For functions, C# also employs the term
methods. This is an illustration of how to declare
and use a method:
The C Sharp class eClass
Verdict Summaries:
JAVA: Java offers ternary operators, switch-case,
and if-else decision statements, among other
decision statements.
The age of Java is 25.
You are an adult if age >= 18; else, you are not an
adult if age < System.out.println("You are not an
adult."); }
// Switch-case statement: String dayName; int
dayOfWeek = 3.
swap (dayOfWeek) { case 1: dayName =
"Monday"; break; case 2: dayName = "Tuesday";
break; //... default: dayName = "Invalid day";}
// Ternary function
Character outcome = (age >= 18)? "Adult": "Not
qualified as an adult";
C#: For decision-making, C# additionally has the
if-else, switch-case, and ternary operators.
The age of {csharp} is 25.
If (youth >= 18) {
PHP: Other decision-making tools supported by
PHP include the ternary operator, switch-case,
and if-else.
$age_{php} = 25;
If ($age >= 18), then {echo "You are an adult.";
else { echo "You are not an adult."; }
// Case-switching assertion
$dayName; $dayOfWeek = 3;
swap ($dayOfWeek) { case 1: $dayName =
"Monday"; break; case 2: $dayName =
"Tuesday"; break; //... default: $dayName =
"Invalid day";}
// Ternary operator: $age >= 18) = result?
"Adult": "Not qualified as an adult";
Loop Declarations:
JAVA: The for, while, and do-while loop
statements are among the loop statements
available in Java.
Java // For loop for (int i = 0, i 5, and i++) It is
System.out.println(i);
Python provides for loop, while loop, and a
different syntax for do-while-like functionality.
`python
For loop for i in range(5):
print(i)
While loop i = 0 while i < 5: print(i) i += 1
Do-while-like functionality i = 0 while True:
print(i) i += 1 if i >= 5: break `
PHP: PHP is also capable of supporting while
loops, for loops, and an alternative syntax for do-
while-like operations.
{php}// For loop for ($i = 0; $i < 5; $i++) {echo $i;}
// Looping while
$i < 5; nevertheless, $i = 0 ~
static void Main where args are string
console.addNumbers(5, 10); int
sum.WriteLine(sum + "Sum: ");}
Returning a + b; static int AddNumbers(int a, int