Determine if a value is positive, negative, or zero : If « Language Basics « C# / C Sharp






Determine if a value is positive, negative, or zero

Determine if a value is positive, negative, or zero
/*
C#: The Complete Reference 
by Herbert Schildt 

Publisher: Osborne/McGraw-Hill (March 8, 2002)
ISBN: 0072134852
*/
// Determine if a value is positive, negative, or zero. 
using System; 
 
public class PosNegZero {  
  public static void Main() { 
    int i; 
 
    for(i=-5; i <= 5; i++) { 
 
      Console.Write("Testing " + i + ": "); 
 
      if(i < 0) Console.WriteLine("negative"); 
      else if(i == 0) Console.WriteLine("no sign"); 
        else Console.WriteLine("positive"); 
    } 
 
  } 
}


           
       








Related examples in the same category

1.If else for intIf else for int
2.Determine if a value is positive or negativeDetermine if a value is positive or negative
3.Demonstrate the ifDemonstrate the if
4.Demonstrate a block of codeDemonstrate a block of code
5.If BranchingIf Branching
6.If ElseIf Else
7.Another if elseAnother if else
8.Illustrates the use of the if statementIllustrates the use of the if statement
9.Illustrates the use of an if statement that executes a blockIllustrates the use of an if statement that executes a block
10.illustrates the use of a nested if statementillustrates the use of a nested if statement
11.Logical operators with an if statementLogical operators with an if statement