Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- static void rainfall() {
- try {
- System.out.print("Enter the file name with extension : ");
- // C:\Users\Rach2o4u\workspace\Project 4\src\rainfall.txt
- Scanner input = new Scanner(System.in);
- File file = new File(input.nextLine());
- input.close();
- input = new Scanner(file);
- do {
- String line2 = input.nextLine();
- double value1 = Double.parseDouble(line2);
- if (value1 == -999)
- break;
- String line = null;
- double sum = 0;
- double count = 0;
- while ((line = input.nextLine()) != null) {
- String[] vals = line.split(" ");
- for(int i = 0; i < vals.length; i++) {
- sum += Double.valueOf(vals[i].trim());
- count++;
- }
- }
- System.out.println("the average is = " + ((double) sum / count));
- System.out.println(value1);
- } while (input.hasNextLine());
- input.close();
- } catch (Exception ex) {
- ex.printStackTrace();
- }
- }
- private static int countnums(String file) {
- int count = 0;
- if (line.charAt(0) != ' ') {
- count++;
- }
- for (int i = 0; i < line.length(); i++) {
- if ((line.charAt(i) == ' ')) {
- count++;
- }
- }
- return count;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement