0% found this document useful (0 votes)
3 views

Explanation of Differences

The document outlines key differences between C# and Java in terms of input handling, loop structures, and control flow statements. It highlights specific features such as the use of Console methods in C# instead of the Scanner class, and similarities in loop behavior across both languages. Additionally, it notes that C# has more advanced capabilities in its switch statements compared to Java.

Uploaded by

rowena olayon
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

Explanation of Differences

The document outlines key differences between C# and Java in terms of input handling, loop structures, and control flow statements. It highlights specific features such as the use of Console methods in C# instead of the Scanner class, and similarities in loop behavior across both languages. Additionally, it notes that C# has more advanced capabilities in its switch statements compared to Java.

Uploaded by

rowena olayon
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1

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.

break, continue, and goto in Loops

 break: Exits the loop immediately.


 continue: Skips the current iteration and proceeds to the next.
 goto: Can jump to a labeled statement (not commonly recommended).

Explanation:

1. break in for Loop:


o Terminates the loop when i == 3.
2. continue in while Loop:
o Skips the current iteration when j == 3 and continues with the next iteration.
3. return in do-while Loop:
o Exits the method entirely when k == 4.

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.

You might also like