Skip to content
Snippets Groups Projects
Commit 8a415f01 authored by Vesa Lappalainen's avatar Vesa Lappalainen :bicyclist:
Browse files

ht6 alku

parent 0fb269f8
No related branches found
No related tags found
No related merge requests found
package tiedosto;
import java.io.*;
/**
* Ohjelmalla tulostetaan kertotaulu tiedostoon. Jos tiedosto on
* olemassa, jatketaan vanhan tiedoston perään.
* @author Vesa Lappalainen
* @version 1.0, 21.02.2003
* @version 1.1, 4.03.2012
*/
public class Kertotaulu7 {
/**
* Kertotaulu tiedostoon.
* @param args tiedoston nimi
* @example
* <pre name="test">
* #THROWS IOException
* #import java.io.IOException;
* #import fi.jyu.mit.ohj2.VertaaTiedosto;
* String tiednimi = "kertotaulu7koe.txt";
* VertaaTiedosto.tuhoaTiedosto(tiednimi);
* main(new String[]{tiednimi});
* String tulos = " 0 * 5 = 0\n"+
* " 1 * 5 = 5\n"+
* " 2 * 5 = 10\n"+
* " 3 * 5 = 15\n"+
* " 4 * 5 = 20\n"+
* " 5 * 5 = 25\n"+
* " 6 * 5 = 30\n"+
* " 7 * 5 = 35\n"+
* " 8 * 5 = 40\n"+
* " 9 * 5 = 45\n";
* VertaaTiedosto.vertaaFileString(tiednimi,tulos) === null;
* main(new String[]{tiednimi});
* VertaaTiedosto.vertaaFileString(tiednimi,tulos+tulos) === null;
* VertaaTiedosto.tuhoaTiedosto(tiednimi);
* </pre>
*/
public static void main(String[] args) {
String tiedNimi = "taulu.txt";
if (args.length > 0 ) tiedNimi = args[0];
try (PrintStream fo = new PrintStream(new FileOutputStream(tiedNimi, true))) {
int kerroin = 5;
for (int i = 0; i <= 10; i++)
fo.printf("%2d * %d = %3d\n", i, kerroin, i * kerroin);
} catch (FileNotFoundException ex) {
System.err.println("Tiedosto ei aukea: " + ex.getMessage());
}
}
}
\ No newline at end of file
0 * 5 = 0
1 * 5 = 5
2 * 5 = 10
3 * 5 = 15
4 * 5 = 20
5 * 5 = 25
6 * 5 = 30
7 * 5 = 35
8 * 5 = 40
9 * 5 = 45
0 * 5 = 0
1 * 5 = 5
2 * 5 = 10
3 * 5 = 15
4 * 5 = 20
5 * 5 = 25
6 * 5 = 30
7 * 5 = 35
8 * 5 = 40
9 * 5 = 45
10 * 5 = 50
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment