Friday 24 June 2016

C# Tutorial - For Beginners & Professionals Understanding decision making statements in C#



Decision making statements help you to make decision based on certain conditions. These conditions are specified by a set of decision making statements having boolean expressions which are evaluated to a boolean value true or false. There are following types of decision making statements in C#.
  1. If statement

    An if statement consists of a boolean expression which is evaluated to a boolean value. If the value is true then if block is executed otherwise next statement(s) would be executed.
    You can have multiple if statement as shown below-
    1. public class Example
    2. {
    3. static void Main()
    4. {
    5. int a = 5, b = 2;
    6. int result = a / b;
    7.  
    8. if (result == 2)
    9. {
    10. Console.WriteLine("Result is 2");
    11. }
    12. if (result == 3)
    13. {
    14. Console.WriteLine("Result is 3");
    15. }
    16. }
    17. }
    18. /* Output
    19. Result is 2
    20. */
    You can also do nesting of if statement means an if statement inside another if that is called nested if statement.
  2. If-Else statement

    An if-else statement consists of two statements – if statement and else statement. When the expression in an if-statement is evaluated to true then if block is executed otherwise the else block would be executed.
    1. public class Example
    2. {
    3. static void Main()
    4. {
    5. int a = 5, b = 6;
    6. int result = a - b;
    7. if (result > 0)
    8. {
    9. Console.WriteLine("Result is greater than zero");
    10. }
    11. else
    12. {
    13. Console.WriteLine("Result is smaller than or equal to zero");
    14. }
    15. }
    16. }
    17. /* Output
    18. Result is smaller than or equal to zero
    19. */
  3. If-Else-If statement or ladder

    The If-Else-If ladder is a set of statements that is used to test a series of conditions. If the first if statement meet the result then code within the if block executes. If not, control passes to the else statement, which contains a second "if" statement. If second one meet the result then code within the if block executes. This continues as a series of else if statements. A default else code block may execute when no condition has been evaluated to true.
    If-Else-If ladder must contain more specific case at the top and generalize case at the bottom.
    1. public class Example
    2. {
    3. static void Main(string[] args)
    4. {
    5. char grade = 'B';
    6.  
    7. if (grade == 'A')
    8. {
    9. Console.WriteLine("Excellent!");
    10. }
    11. else if (grade == 'B')
    12. {
    13. Console.WriteLine("Well done");
    14. }
    15. else if (grade == 'D')
    16. {
    17. Console.WriteLine("You passed");
    18. }
    19. else if (grade == 'F')
    20. {
    21. Console.WriteLine("Better try again");
    22. }
    23. else
    24. {
    25. Console.WriteLine("You Failed!");
    26. }
    27. }
    28. }
    29. /* Output
    30. Well done
    31. */
  4. Switch statement

    Switch statement acts as a substitute for long If-Else-If ladder that is used to test a series of conditions. A switch statement contains one or more case labels which are tested against the switch expression.
    When one case matches the value with the result of switch expression, the control continues executing the code from that label. When no case label contains a matching value, control is transferred to the default section, if it exists. If there is no default section, no action is taken and control is transferred outside the switch statement.
    1. public class Example
    2. {
    3. static void Main(string[] args)
    4. {
    5. char grade = 'B';
    6.  
    7. switch (grade)
    8. {
    9. case 'A':
    10. Console.WriteLine("Excellent!");
    11. break;
    12. case 'B':
    13. case 'C':
    14. Console.WriteLine("Well done");
    15. break;
    16. case 'D':
    17. Console.WriteLine("You passed");
    18. break;
    19. case 'F':
    20. Console.WriteLine("Better try again");
    21. break;
    22. default:
    23. Console.WriteLine("You Failed!");
    24. break;
    25. }
    26. }
    27. }
    28. /* Output
    29. Well done
    30. */

    Key points about Switch statement

    1. Each case label specifies a constant value.
    2. A switch statement can have multiple switch sections, and each section can have one or more case labels.
    3. Unlike C and C++, C# does not allow continuing execution from one switch section to the next. It means each switch section must be separated by a break or other jump statement such as goto, return and throw.
    4. Unlike If-Else-If ladder, it is not mandatory to put more specific case at the top and generalize case at the bottom since all the switch cases have equal precedence.
What do you think?
I hope you will enjoy the decision making statements while programming with C#. I would like to have feedback from my blog readers. Your valuable feedback, question, or comments about this article are always welcome.
Read More »

Tuesday 21 June 2016

The Path to Higher Education Through the Eyes of Search

Like many sectors, education can be evaluated in part by its performance in Google search queries. In this Hangout On Air, Jen Howard, Google's Education Industry Director, discusses how the education landscape fared in search during the third quarter of 2013. This includes the fact that demand for education maintained growth, traditional schools had a 7% year-over-year increase and nursing topped the fastest-growing program terms.
Published
October 2013
Topics
 
 
 Across all the major categories that we evaluate, growth continued to happen in Q3.
- Jennifer Howard, Director of Education, Google
Read More »

Java Interview Programs

  1. Find out duplicate number between 1 to N numbers.
  2. Find out middle index where sum of both ends are equal.
  3. Write a singleton class.
  4. Write a program to create deadlock between two threads.
  5. Write a program to reverse a string using recursive algorithm.
  6. Write a program to reverse a number.
  7. Write a program to convert decimal number to binary format.
  8. Write a program to find perfect number or not.
  9. Write a program to implement ArrayList.
  10. Write a program to find maximum repeated words from a file.
  11. Wrie a program to find out duplicate characters in a string.
  12. Write a program to find top two maximum numbers in a array.
  13. Write a program to sort a map by value.
  14. Write a program to find common elements between two arrays.
  15. How to swap two numbers without using temporary variable?
  16. Write a program to print fibonacci series.
  17. Write a program to find sum of each digit in the given number using recursion.
  18. Write a program to check the given number is a prime number or not?
  19. Write a program to find the given number is Armstrong number or not?
  20. Write a program to convert binary to decimal number.
  21. Write a program to check the given number is binary number or not?
  22. Write a program for Bubble Sort in java.
  23. Write a program for Insertion Sort in java.
  24. Write a program to implement hashcode and equals.
  25. How to get distinct elements from an array by avoiding duplicate elements?
  26. Write a program to get distinct word list from the given file.
  27. Write a program to get a line with max word count from the given file.
  28. Write a program to convert string to number without using Integer.parseInt() method.
  29. Write a program to find two lines with max characters in descending order.
  30. Write a program to find the sum of the first 1000 prime numbers.
  31. Find longest substring without repeating characters.
  32. Write a program to remove duplicates from sorted array.
  33. How to sort a Stack using a temporary Stack?
Read More »