Lucky Cat Tutoring Services

CIT 111: Booleans & Other Primitive Data Types
September 1, 2009, 3:31 pm
Filed under: Uncategorized | Tags: , ,

Booleans: Can hold true or false, can be assigned any way that we want them, as long as the expression evaluates to “true or false”.


// A program for demonstrating boolean variables

public class TrueFalse
public static void main(String[] args)
boolean bool;
int a=18, b=12;
bool = true;
bool = false;
bool = a > b;
if (bool)
{System.out.println(“‘a’ is larger than ‘b'”);

Should come out to say:

‘a’ is larger than ‘b’

Process completed.

CHARS: are letter based only; can only hold a single character.

// This program demonstrates the char data type.

public class Letters
public static void main(String[] args)
char letter;

letter = ‘A’;
letter = ‘B’;

-Errors occur when more than one character is used. Char can only use ONE.

-Double quotes “” around the single character makes it the wrong data type. Anything with “” is a STRING not a CHAR!! Single quotes must always be used

Chars and Integer relationships:
Letters can be assigned using numeric value for a letter in Java 6.


Leave a Comment so far
Leave a comment

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: