Advertisement
Guest User

Zad3

a guest
Nov 22nd, 2017
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.93 KB | None | 0 0
  1. package cialem;
  2.  
  3. import java.util.*;
  4. import java.io.*;
  5.  
  6. public class Autobus {
  7.  
  8.     public static void main(String[] args) throws FileNotFoundException {
  9.        
  10.         /*
  11.           Pobierz z pliku 'a.txt' 10 liczb, dodaj do kazdej liczby z pliku 'b.txt',
  12.           a nastepnie zapisz wyniki w pliku 'c.txt'
  13.           sume wszystkich zapisanych liczb napisz w konsoli
  14.          */
  15.         Scanner s1 = new Scanner(new File("a.txt"));
  16.         Scanner s2 = new Scanner(new File("b.txt"));
  17.         PrintStream pc = new PrintStream("c.txt");
  18.         int a,b,c,suma=0;
  19.        
  20.        
  21.         for(int i=0;i<10;i++)
  22.         {
  23.             c=0;
  24.             /*
  25.             String l1 = s1.nextLine();
  26.             String l2 = s2.nextLine();
  27.             a=Integer.parseInt(l1);
  28.             b=Integer.parseInt(l2);
  29.             */
  30.             /*
  31.             a = s1.nextInt();
  32.             b = s2.nextInt();
  33.            
  34.             c=a+b;
  35.             */
  36.            
  37.             c = s1.nextInt() + s2.nextInt();
  38.             pc.println(c);
  39.             suma=suma+c;
  40.         }
  41.        
  42.         System.out.println(suma);
  43.         s1.close();
  44.         s2.close();
  45.         pc.close();
  46.        
  47.     }
  48.  
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement