Object-Oriented Programming (From Problem Solving to JAVA) (Charles River Media Programming)
10.2 Declaring Strings
String variables are of type string and can be declared with or without their values, in a similar manner to the variables of primitive types. The following declares a string variable, message.
string message
A value of type string is a string constant enclosed in quotes. For example, the following statement assigns a string value to the string variable message.
set message = "Hello, world!"
A string variable can be declared with a value; the following declares string variable s2 with the string constant "Hi, everyone!".
string s2 = "Hi, everyone"
The two string variables just declared can be displayed on the console with the following statements:
display message display s2
When executing the program that includes these two statements, the following message will appear on the screen:
Hello, world! Hi, everyone
Категории