Tuesday, February 11, 2014

Suppose there are two values stored in the add.txt, read those integers from the file and display their sum on the console.

//Scanner2.java

import java.util.Scanner;
import java.io.*;

public class Scanner2
{
    public static void main(String surat[]) throws IOException
{
        Scanner s=new Scanner(new File("add.txt"));

        int n1=s.nextInt();
        int n2=s.nextInt();

        System.out.println(n1+n2);
    }
}

//add.txt

10
20

Output:


No comments:

Post a Comment