
Write a Java program that prompts the user to enter an integer. The program will then read a list of integers from a file named numbers.txt. Next, it will sum up all the numbers in the file which are larger than the integer value given by the user earlier, and display the sum of all those numbers. Use classes and methods from the java.io package for all input.

Java Number Example
import java.io.*;
import java.util.*;
class NumberExample{
public static void main(String[] args) throws Exception{
ArrayList list=new ArrayList();
int sum=0;
System.out.println("Enter number:");
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
int num=Integer.parseInt(br.readLine());
BufferedReader reader=new BufferedReader(new FileReader(new File("C:/numbers.txt")));
String st="";
while((st = reader.readLine())!= null) {
list.add(Integer.parseInt(st));
}
for(int i=0;i<list.size();i++){
if(Integer.parseInt(list.get(i).toString())>num){
sum+=Integer.parseInt(list.get(i).toString());
}
}
System.out.println("Sum of integers that are greater than "+num+": "+sum);
}
}
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.