Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa Java-Beginners add the numbers and print the output
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


ganesh pardeshi
add the numbers and print the output
1 Answer(s)      2 years and 9 months ago
Posted in : Java Beginners


There will be 5 numbers (each in a new line) written in a text file. Text file name will be ?input2.txt?. Your Java code should read that text file, add all the numbers and print the output in a new file named ?output2.txt?.


Advertisement
View Answers

March 26, 2012 at 11:03 AM


import java.io.*;
class ReadNumbersFromFile
{
    public static void main(String[] args) 
    {
        try{
        BufferedReader br=new BufferedReader(new FileReader("input.txt"));
        String str="";
        int sum=0;
        while((str=br.readLine())!=null){
            int num=Integer.parseInt(str);
            sum+=num;
        }
        br.close();
        BufferedWriter bw=new BufferedWriter(new FileWriter("output.txt"));
        bw.write(Integer.toString(sum));
        bw.close();
        System.out.println("Data has been written in the file.");
        }
        catch(Exception E){}
    }
}


Related Tutorials/Questions & Answers:
print numbers
print numbers  1234 123 12 1234   1234 123 12 1234
print numbers in traingle shape
print numbers in traingle shape  1 22 333 4444 i want output like this please help me   class Pyramid { public static void main(String[] args) { for(int i=1;i<=4;i++){ for(int j=1;j<
Advertisements
how to add to numbers in java
how to add to numbers in java  how to add to numbers in java
Application for print pyramid of numbers
Application for print pyramid of numbers  What is the code for printing the numbers like 1 1 1 1 2 2 1 1 3 4 3 1 1 4 7 7 4 1
Applet for add two numbers
); add(text2); label3 = new Label("Sum of Two Numbers: "); label3.setBounds(20,80,130,20); add(label3); output = new TextField(5); output.setBounds(150,80,100,20); add(output
print 100 numbers using loops
print 100 numbers using loops  how to print from 1 to 100 using for loop ?   Hi Friend, You can use the following code: class Loop...); } } } Thanks   class Numbers { public satic void main
Add two big numbers
Add two big numbers       In this section, you will learn how to add two big numbers... that takes both numbers. Now, you will have to define it and use the add() method
Add Two Numbers in Java
Add Two Numbers in Java     ... these arguments and print the addition of those numbers. In this example, args... into integer type. Now you can add these values into a sum variable and print
Print Output in C LAnaguage - Development process
Print Output in C LAnaguage  I want to Print Following Output in C Language with Combined For Loops Not Seprate Loops pleaseHelp Me
print the even numbers between the range 100-200
print the even numbers between the range 100-200  Q ?write an application that print out the even numbers between the range 100-200 ? 1- which aer not divisible by 7 and 5 ? 2- Number of the numbers which are not divisible
add tow numbers with out using arthamatic operaters
add tow numbers with out using arthamatic operaters  add tow numbers with out using arthamatic operaters
Add Complex Numbers Java
How to Add Complex Numbers Java In this Java tutorial section, you will learn how to add complex Numbers in Java Programming Language. As you are already...)); } } Output -2-3i -4-5i Addition of Complex Numbers are :-6-8i
C Program to Print Following Output - Development process
C Program to Print Following Output  Hello Sir I wnat to print Followning output in C Language with for loop How I Can Print it? 5 5 4 5 4 3 5 4 3 2 5 4 3 2 1  Hi Friend, Try the following: #include
How to print the following output using c program
How to print the following output using c program  1) 4 3 4 2 3 4 1 2 3 4 2) A B C D E F G H I J
How to print a equilateral triangle patren with numbers
How to print a equilateral triangle patren with numbers  I figure out how to use for loop to print the triangle but i couldn't get the exact values as this http://im37.gulfup.com/FzrOb.jpg could you please help me
Add two big numbers - Java Beginners
Add two big numbers - Java Beginners  Hi, I am beginner in Java and leaned basic concepts of Java. Now I am trying to find example code for adding big numbers in Java. I need basic Java Beginners example. It should easy
how to write a program in java to print numbers in equalateral triangle
how to write a program in java to print numbers in equalateral triangle  the output must be 1 324 76589   Here is an example of pattern 1 2 3 4 5 6 7 8 9 Example: public class NumberTriangle{ public
write an application that print out the even numbers between the range 100-200
write an application that print out the even numbers between the range 100-200   write an application that print out the even numbers between... and determine the even numbers between them. class EvenNumbers { public static
how to sort the elements of hashmap and to print output the key and the value attached to it
how to sort the elements of hashmap and to print output the key and the value attached to it  how to sort the elements of hashmap and to print output the key and the value attached
output
output  Sir,I am experiencing some problems with the output of this program.I got some useful help this website,but the output of the program isn't producing what it should.let me explain the output below is what happen when
Print
itself, representing standard output, is an instance of java.io.PrintStream class. Standard output is, on most operating systems, console output. println: It is a method of java.io.PrintStream class that lets you output some text
JavaScript determine add, product of two numbers
JavaScript determine add, product of two numbers In this section, you... numbers. To find this, we have created two textboxes and four button...; function add(){ var num1=document.form.text1.value; var num2
print
print  How to print JFrame All Componant?   Please visit the following link: http://www.roseindia.net/java/example/java/swing/Print.shtml
add
How to add two int numbers in Java Example  How to add two int numbers in Java Example  Here is a java example that accepts two integer from the user and find their sum. import java.util.*; class AddNumbers
add
How to add two numbers in Java  add two number   Here is a java example that accepts two integer from the user and find their sum. import java.util.*; class AddNumbers { public static void main(String[] args
What will be the Output?
What will be the Output?  int[] number = {5,3,6,10,1} int temp; for (int i=0; inumbers[j]) { temp=numbers[i]; numbers[i]=numbers[j] number[j]=temp
add
add two no in Java  Java Add Example that accepts two integer from the user and find their sum  Here is a java example that accepts two integer from the user and find their sum. import java.util.*; class AddNumbers
add
Java Example to add two numbers  Java Example to add two numbers  Here is a java example that accepts two integer from the user and find their sum. import java.util.*; class AddNumbers { public static void main
add
Java Program to add two numbers  Java Program to add two numbers  Here is a java example that accepts two integer from the user and find their sum. import java.util.*; class AddNumbers { public static void main
Displaying checked checkbox in same page as well as print on another page ....also add next pages cheches checkbox into previous list
Displaying checked checkbox in same page as well as print on another page ....also add next pages cheches checkbox into previous list  1..., it does not display previous page's selected checkboxes. So, i want such output
Add two number in java
add these value into z variable and print the z variable to the console...Add two number in java In this section you will learn about how to add two... be added, So two add,  convert these String into numeric type
Advertisements
 

 

 

DMCA.com