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:
Status: Offline
Joined: Aug 11, 201113Year Member
Posts: 264
Reputation Power: 12
Status: Offline
Joined: Aug 11, 201113Year Member
Posts: 264
Reputation Power: 12
Thought I'd put together an example of an IF&ELSE statement.
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
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:
Status: Offline
Joined: Jul 12, 201014Year Member
Posts: 3,612
Reputation Power: 173
Status: Offline
Joined: Jul 12, 201014Year Member
Posts: 3,612
Reputation Power: 173
Why aren't you just setting the value of postcount while declaring the variable?
int postcount = 15;
int postcount = 15;
- 0useful
- 0not useful
#3. Posted:
Status: Offline
Joined: Aug 11, 201113Year Member
Posts: 264
Reputation Power: 12
Status: Offline
Joined: Aug 11, 201113Year 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.
- 0useful
- 0not useful
You are viewing our Forum Archives. To view or take place in current topics click here.