Ohjelmointi 2 / 2011
jono maski "Kissa" "K?ss?" => samat "Kiss" "K?ss?" => ei samat
public static boolean onkoSamatKys(String jono, String maski);
...
if ( onkoSamatKys("Kissa","K?ss?") ) ...
jono poista tulos Catcat at => Cc Paatti at => Pi Puatit at => Puit
ks. Viitteet.java:
int a;
StringBuffer b = new StringBuffer("1");
StringBuffer c = new StringBuffer("2");
StringBuffer p;
a = 19;
p = b;
p.append("0");
p = c;
p.append(a);
c = b;
c.append("3");
a = 19 p = b p.app(0) p = c p.app(a) c = b c.app(3)
+-----+ +-----+ +-----+ +-----+ +-----+ +-----+ +-----+
100 | | a | | | | | | | | | | | |
+-----+ +-----+ +-----+ +-----+ +-----+ +-----+ +-----+
104 |900 | b | | | | | | | | | | | |
+-----+ +-----+ +-----+ +-----+ +-----+ +-----+ +-----+
108 |940 | c | | | | | | | | | | | |
+-----+ +-----+ +-----+ +-----+ +-----+ +-----+ +-----+
112 | ?? | p | o+- | o+- | o+- | o+- | o+- | o+-
+-----+ +-----+ +-----+ +-----+ +-----+ +-----+ +-----+
Keko:
+-----+ +-----+ +-----+ +-----+ +-----+ +-----+ +-----+
900 | 1 | | | | | | | | | | | | |
+-----+ +-----+ +-----+ +-----+ +-----+ +-----+ +-----+
940 | 2 | | | | | | | | | | | | |
+-----+ +-----+ +-----+ +-----+ +-----+ +-----+ +-----+
jono maski "Kissa" "K*a" => samat "Kissa" "K*i" => ei samat "Kissa" "K*" => samat "Lintu" "K*" => ei samat
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"> <html> <head> <base target=m1> </head> <body> 93 <a href="vesal/index.html?r=">Vesa Lappalainen</a> = 8.5<br> 94 <a href="mattim/index.html?r=">Matti Meikäläinen</a> = 8<br> 95 <a href="teppot/index.html?r=">Teppo Teikäläinen</a> = 9<br> </body> </html> ja tee sitten ohjelma, joka lukee tiedoston ja tulostaa sen muodossa: 93 Vesa Lappalainen = 8.5 - vesal 94 Matti Meikäläinen = 8 - mattim 95 Teppo Teikäläinen = 9 - teppot
String s = Syotto.kysy("Anna jono");
System.out.println("Jono oli: \"" + s + "\"");
import java.io.*;
/**
* Luetaan tiedosto ja tulostetaan se näytölle.
* @author Vesa Lappalainen
* @version 1.0, 25.01.2002
*/
public class TiedostonLukeminen {
public static void main(String[] args) throws IOException {
BufferedReader f = null;
try {
f = new BufferedReader(new FileReader("TiedostonLukeminen.java"));
} catch (FileNotFoundException ex) {
System.out.println("Tiedosto ei aukea!"); return;
}
try {
String rivi;
while ( ( rivi = f.readLine() ) != null ) {
System.out.println(rivi);
}
} catch (IOException ex) {
System.out.println("Vikaa tiedostoa lukiessa!"); return;
} finally {
f.close();
}
}
}
String s = "123";
int i = Mjonot.erotaInt(s,0);