Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- import java.io.*;
- class Assignment5{
- public static void main(String[] args)throws Exception{
- String data;
- ArrayList<Double> store = new ArrayList<Double>();
- Scanner scanner = new Scanner(System.in);
- System.out.println(" ");
- System.out.println("Please enter the name of a file with .txt at the end.");
- System.out.println(" ");
- data = scanner.nextLine();
- File inputFile = new File(data);
- Scanner reader = new Scanner(inputFile);
- while(reader.hasNext()){
- store.add(reader.nextDouble());
- }
- calculateSum(store);
- store.clear();
- }
- private static void calculateSum(ArrayList<Double> ArrayList){
- double sum = 0;
- double avg = 0;
- double total = 0;
- double totalrainfall = 0;
- Iterator<Double> iterator = ArrayList.iterator();
- while(iterator.hasNext()){
- sum += iterator.next();
- }
- total = ArrayList.size();
- avg = (sum / total);
- System.out.println(" ");
- System.out.println("The total rainfall is " + totalrainfall);
- }
- import java.util.*;
- import java.io.*;
- class Assignment5{
- public static void main(String[] args)throws Exception{
- String data;
- ArrayList<Double> store = new ArrayList<Double>();
- Scanner scanner = new Scanner(System.in);
- System.out.println(" ");
- System.out.println("Please enter the name of a file with .txt at the end.");
- System.out.println(" ");
- data = scanner.nextLine();
- File inputFile = new File(data);
- Scanner reader = new Scanner(inputFile);
- while(reader.hasNext()){
- store.add(reader.nextDouble());
- }
- calculateSum(store);
- store.clear();
- }
- private static void calculateSum(ArrayList<Double> ArrayList){
- double sum = 0;
- double avg = 0;
- double total = 0;
- double totalrainfall = 0;
- Iterator<Double> iterator = ArrayList.iterator();
- while(iterator.hasNext()){
- sum += iterator.next();
- }
- total = ArrayList.size();
- avg = (sum / total);
- System.out.println(" ");
- System.out.println("The total rainfall is " + totalrainfall);
- }
- 80.0
- 70.0
- 75.0
- // ...
- import java.util.;
- import java.io.;
- class Assignment5
- {
- public static void main(String[] args) throws Exception
- {
- String data;
- int[] store = new int[12];
- Scanner scanner = new Scanner(System.in);
- System.out.println(" ");
- System.out.println("Please enter the name of a file with .txt at the end.");
- System.out.println(" ");
- data = scanner.nextLine();
- File inputFile = new File(data);
- Scanner reader = new Scanner(inputFile);
- while(reader.hasNext())
- {
- String currentLine = scanner.nextLine();
- String[] currentMonthDetails = currentLine.split(".");
- int currentMonth = Integer.parseInt(currentMonthDetails[0]);
- int currentRainfall = Integer.parseInt(currentMonthDetails[1]);
- store[currentMonth] = currentRainfall;
- }
- calculateSum(store);
- store = null;
- }
- private static void calculateSum(int[] aRainfallData)
- {
- int avgRainfall = 0;
- int numberOfMonths = 0;
- int totalRainfall = 0;
- numberOfMonths = aRainfallData.length;
- for (int index=0; index < numberOfMonths ; index++)
- {
- totalRainfall += aRainfallData[index];
- }
- avgRainfall = (totalRainfall / numberOfMonths );
- System.out.println(" ");
- System.out.println("The total rainfall is " + totalRainfall );
- }
- }
- double sum = 0;
- boolean toggle = false;
- for(Object d: arrayList) {
- [...]
- if(toggle) {
- sum += (Double)d;
- toggle = !toggle;
- }
- }
Add Comment
Please, Sign In to add comment