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






Determine if a value is positive or negative

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

Publisher: Osborne/McGraw-Hill (March 8, 2002)
ISBN: 0072134852
*/
// Determine if a value is positive or negative. 
using System; 
 
public class PosNeg {  
  public static void Main() { 
    int i; 
 
    for(i=-5; i <= 5; i++) { 
      Console.Write("Testing " + i + ": "); 
 
      if(i < 0) Console.WriteLine("negative"); 
      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, negative, or zeroDetermine if a value is positive, negative, or zero
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