Cod sursa(job #1547231)

Utilizator x3medima17Dima Savva x3medima17 Data 9 decembrie 2015 09:33:05
Problema A+B Scor 0
Compilator java Status done
Runda Arhiva de probleme Marime 1.79 kb
package com.company;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;

public class Main {

    public static void main(String[] args) throws IOException
    {
	// write your code here
        Scanner s = new Scanner("adunare.in");
        int a = (s.nextInt());
        int b = (s.nextInt());
//        System.out.println(s.read());
        Writer w = new Writer("adunare.out");
        int n = a + b;
        w.write(Integer.toString(n));
    }
}


class Writer
{
    FileOutputStream file;

    Writer(String fname) throws IOException
    {
        file = new FileOutputStream(fname);
    }

    void write(String str) throws IOException
    {
        file.write(str.getBytes());
    }
}
class Scanner
{
    FileInputStream file;
    boolean hasNext = true;
    Scanner(String fname) throws  IOException
    {
        file = new FileInputStream(fname);
    }


    int nextInt() throws IOException
    {
        String out = "";
        int b = '5';
        while(b != -1 && (b >= '0' && b <= '9'))
        {
            b = file.read();
//            System.out.printf("%d\n",b);

            if(b == -1)
                hasNext = false;
            else if(b >= '0' && b <= '9')
                out += (char)b;
        }
        file.read();
//        System.out.println("a"+out+"b");
        return Integer.parseInt(out);
    }

    String read() throws IOException
    {
        int b = 0;
        String out = new String();
        while (b != -1)
        {
            b = file.read();
            if (b ==  -1)
                hasNext = false;
            else
                out += b+"\n";
        }
        return out;
    }

    boolean hasNext()
    {
        return hasNext;
    }


}