Explanation of Differences
Explanation of Differences
1. Input Handling:
o C# uses Console.ReadLine() to read input as a string and int.TryParse() to
safely convert it to an integer.
2. Scanner Replacement:
o The Scanner class in Java is replaced by Console methods in C#.
3. String Concatenation:
o Similar to Java, string concatenation in C# is done using the + operator.
4. Closing Resources:
o No need to explicitly close a resource like Scanner in C#, as Console methods
are part of the runtime.
Explanation:
1. while Loop:
o The while loop in C# behaves exactly as in Java, repeatedly executing the block
as long as the condition is true.
2. do-while Loop:
o The do-while loop guarantees at least one execution before checking the
condition, just like in Java.
3. for Loop:
o The for loop in C# is identical to Java in syntax and behavior.
4. foreach Loop:
o The foreach loop in C# is similar to Java's enhanced for loop, iterating over
each element in a collection or array.
Explanation:
Yes, C# supports the switch construct, similar to Java, and allows cases for both integers and strings
(among other types). However, C# offers more advanced features in its switch statements and
expressions compared to Java.