I needed this to code the Sim City road connection example. I could not get the == thing comaring working so I looked up how to compare strings with each other. This is done with equals. That worked for me. Below you can see how it is done.
/**
* @(#)StringCompare01.java
*
* StringCompare01 Applet application
*
* @author
* @version 1.00 2011/7/21
*/
import java.awt.*;
import java.applet.*;
public class StringCompare01 extends Applet {
public void init() {
}
public void paint(Graphics g) {
String banana = "";
for ( int i = 0 ; i < 9 ; i++){
banana = banana + "0";
}
System.out.println(banana);
if ( banana.equals("000000000")) {
g.drawString("String equals 000000000", 50, 90 );
}
g.drawString("Welcome to Java!!", 50, 60 );
}
}
Geen opmerkingen:
Een reactie posten
Opmerking: Alleen leden van deze blog kunnen een reactie posten.