Cod sursa(job #2447920)

Utilizator wumpJustin Fairchild wump Data 15 august 2019 07:16:22
Problema A+B Scor 0
Compilator java Status done
Runda Arhiva de probleme Marime 0.91 kb
import java.io.File;
import java.io.FileWriter;
import java.util.Scanner;
import java.io.FileNotFoundException;
import java.io.IOException;

/** 
 * Reads in numbers on file.in, one per line.
 * Outputs a number to file.out, that is the sum of the two numbers in file.in.
 * The number itself cannot be greater than 2,000,000, and if it is, return the limit
 */
public class Main {
    Main() {
    }
    
    public static void main(String[] args) throws FileNotFoundException, IOException {
        Scanner in = new Scanner(new File("file.in"));
        Integer a = in.nextInt();
        Integer b = in.nextInt();
        in.close();

        Integer limit = 2 * (int) Math.pow(10, 6);
        Integer c = a + b;
        if ((a >= limit) || (b >= limit) || (c >= limit)) {
            c = limit;
        }

        FileWriter out = new FileWriter(new File("file.out"));
        out.append(c.toString());
        out.close();
    }
}