...
In the following example, we initialize an integer to zero, then convert it to a string, then check to see if it is empty. Note the data declaration (highlighted), which is necessary in Java but not in Python. Notice also how verbose Java is, even in an operation as basic as comparing two strings for equality.
Code Block |
---|
language | java |
---|
title | Strings in Java |
---|
| int myCounter = 0;
String myString = String.valueOf(myCounter);
if (myString.equals("0")) ... |
| Code Block |
---|
language | py |
---|
title | Strings in Python |
---|
| myCounter = 0
myString = str(myCounter)
if myString == "0": ... |
|
Code Block |
---|
language | java |
---|
title | Strings in Java |
---|
| // print the integers from 1 to 9
for (int i = 1; i < 10; i++)
{
System.out.println(i);
} |
| Code Block |
---|
language | py |
---|
title | Strings in Python |
---|
| print the integers from 1 to 9
for i in range(1,10):
print i |
|