Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package zpliku;
- import java.io.BufferedReader;
- import java.io.BufferedWriter;
- import java.io.File;
- import java.io.FileNotFoundException;
- import java.io.FileOutputStream;
- import java.io.FileReader;
- import java.io.FileWriter;
- import java.io.IOException;
- import java.io.PrintStream;
- import java.util.ArrayList;
- import java.util.Collections;
- import java.util.Scanner;
- import javax.swing.JOptionPane;
- public class Main {
- public static void main(String[] args) throws FileNotFoundException {
- zapisz();
- parzyste();
- tylesamo();
- czesctrzecia();
- cztery();
- }
- public static void parzyste() {
- int count=0;
- int c = 0;
- int t=0;
- int j=0;
- try {
- Scanner input = new Scanner(System.in);
- File file = new File("plik.txt");
- input = new Scanner(file);
- while (input.hasNextLine()) {
- String line = input.nextLine();
- //System.out.println(line);
- if(line.length()%2==0) count++;
- }
- System.out.println("Napisow o parzystej dlugosci jest: " + count);
- input.close();
- } catch (Exception ex) {
- ex.printStackTrace();
- }
- }
- public static void tylesamo(){
- int c = 0;
- int t=0;
- int j=0;
- try {
- Scanner input = new Scanner(System.in);
- File file = new File("plik.txt");
- input = new Scanner(file);
- while (input.hasNextLine()) {
- String line = input.nextLine();
- //System.out.println(line);
- for(int i=0; i<line.length(); i++){
- if (line.charAt(i) == '0') c++;
- if (line.charAt(i) == '1') j++;
- }
- if(c==j) t++;
- c=0; j=0;
- }
- System.out.println("Tyle samo zer i jedynek jest: "+ t);
- input.close();
- } catch (Exception ex) {
- ex.printStackTrace();
- }
- }
- public static void czesctrzecia(){
- int jedynki=0;
- int zera=0;
- int onlyzero=0;
- int onlyone=0;
- try {
- Scanner input = new Scanner(System.in);
- File file = new File("plik.txt");
- input = new Scanner(file);
- while (input.hasNextLine()) {
- String line = input.nextLine();
- for (int i=0; i<line.length(); i++){
- if(line.charAt(i) == '0') zera++;
- if(line.charAt(i) == '1') jedynki++;
- }
- if(zera == line.length()) onlyzero++;
- if(jedynki == line.length()) onlyone++;
- zera=0; jedynki=0;
- }
- System.out.println("Zer jest: " + onlyzero);
- System.out.println("Jedynek jest: "+onlyone);
- input.close();
- } catch (Exception ex) {
- ex.printStackTrace();
- }
- }
- public static void cztery(){
- int[] tablica=new int[15];
- try {
- Scanner input = new Scanner(System.in);
- File file = new File("plik.txt");
- input = new Scanner(file);
- while (input.hasNextLine()) {
- String line = input.nextLine();
- if(line.length()==2) tablica[0]++;
- if(line.length()==3) tablica[1]++;
- if(line.length()==4) tablica[2]++;
- if(line.length()==5) tablica[3]++;
- if(line.length()==6) tablica[4]++;
- if(line.length()==7) tablica[5]++;
- if(line.length()==8) tablica[6]++;
- if(line.length()==9) tablica[7]++;
- if(line.length()==10) tablica[8]++;
- if(line.length()==11) tablica[9]++;
- if(line.length()==12) tablica[10]++;
- if(line.length()==13) tablica[11]++;
- if(line.length()==14) tablica[12]++;
- if(line.length()==15) tablica[13]++;
- if(line.length()==16) tablica[14]++;
- }
- int j=2;
- for (int i=0; i<tablica.length; i++){
- System.out.println(j+" znaki: " + tablica[i]);
- j++; }
- input.close();
- } catch (Exception ex) {
- ex.printStackTrace();
- }
- }
- public static void zapisz() throws FileNotFoundException {
- PrintStream console = System.out;
- File file = new File("rozw.txt");
- FileOutputStream fos = new FileOutputStream(file);
- PrintStream ps = new PrintStream(fos);
- System.setOut(ps);
- }
- public static void wczytywanie() {
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement