You are viewing our Forum Archives. To view or take place in current topics click here.
Java If & Else statement: Example
Posted:

Java If & Else statement: ExamplePosted:

8ight
  • Resident Elite
Status: Offline
Joined: Aug 11, 201112Year Member
Posts: 264
Reputation Power: 12
Status: Offline
Joined: Aug 11, 201112Year Member
Posts: 264
Reputation Power: 12
Thought I'd put together an example of an IF&ELSE statement.

public class posting {
  public static void main(String[] args){
    int postcount;
   postcount = 15;
    
     if(postcount>=15){
       System.out.println("You can post!");
     }else{
       System.out.println("You cannot post!");
     }
  }
}


If the postcount is greater or equal to 15 then you are able to post!
if(postcount>=15){
System.out.println("You can post!");


But if the postcount is not greater or equal to 15 it will output "You cannot post!".
}else{
System.out.println("You cannot post!");


- 8ight
#2. Posted:
RDCA
  • TTG Contender
Status: Offline
Joined: Jul 12, 201013Year Member
Posts: 3,612
Reputation Power: 173
Status: Offline
Joined: Jul 12, 201013Year Member
Posts: 3,612
Reputation Power: 173
Why aren't you just setting the value of postcount while declaring the variable?
int postcount = 15;
#3. Posted:
8ight
  • Resident Elite
Status: Offline
Joined: Aug 11, 201112Year Member
Posts: 264
Reputation Power: 12
Status: Offline
Joined: Aug 11, 201112Year Member
Posts: 264
Reputation Power: 12
RDCA wrote Why aren't you just setting the value of postcount while declaring the variable?
int postcount = 15;


Just the way I work with Java, sorry.
Jump to:
You are viewing our Forum Archives. To view or take place in current topics click here.