package pl.am.podstawy.lekcja14;
import java.io.*;
import java.util.Scanner;
public class Pliki {
public static void main(String[] args) throws IOException {
PrintWriter out = new PrintWriter(new FileWriter("out.txt", true));
out.println("siema");
//out.print();
//out.println();
//out.printf();
out.close();
System.out.println(System.getProperty("user.dir"));
//FileReader fileReader;
Scanner scanner = new Scanner(new File("plik.txt"));
while(scanner.hasNext()) {
System.out.println(scanner.nextLine());
}
//scanner.next();
//scanner.nextInt();
//scanner.nextDouble();
scanner.close();
}
}
package pl.am.podstawy.lekcja14;
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;
public class ListaObecnosci {
public static void main(String[] args) throws FileNotFoundException {
Scanner scanner = new Scanner(new File("lista.txt"));
float suma = 0;
int numer = 0;
while(scanner.hasNext()) {
numer++;
String nazwisko = scanner.next();
int ocena = scanner.nextInt();
suma += ocena;
System.out.println(numer + " " + nazwisko + ", ocena: " + ocena);
}
System.out.println("średnia z matematyki: " + suma/ numer);
}
}
package pl.am.podstawy.lekcja14;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Scanner;
public class DodawanieUcznia {
public static void main(String[] args) throws IOException {
Scanner scanner = new Scanner(System.in);
System.out.print("Podaj nazwisko ucznia: ");
String nazwisko = scanner.next();
System.out.print("Podaj ocenę tego ucznia: ");
int ocena = scanner.nextInt();
PrintWriter out = new PrintWriter(new FileWriter("lista.txt", true));
out.print("\n" + nazwisko + " " + ocena);
out.close();
}
}