Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.File;
- import java.io.FileNotFoundException;
- import java.util.Scanner;
- public class WeatherArray {
- public static void main(String[] args)
- throws FileNotFoundException{
- Scanner input = new Scanner(new File("PortlandWeather2011.txt"));
- String head = input.nextLine();
- String head2 = input.nextLine();
- System.out.println(head);
- System.out.println(head2);
- int count = 0;
- while(input.hasNextLine()){
- process(input);
- count++;
- }
- double[] prcp = new double[count];
- double[] snow = new double[count];
- double[] snwd = new double[count];
- double[] tmin = new double[count];
- double[] tmax = new double[count];
- input = new Scanner(new File("PortlandWeather2011.txt"));
- head = input.nextLine();
- head2 = input.nextLine();
- System.out.println(head);
- System.out.println(head2);
- count = 0;
- while(input.hasNextLine()){
- input.next();
- input.next();
- prcp[count] = input.nextDouble();
- snow[count] = input.nextDouble();
- snwd[count] = input.nextDouble();
- tmin[count] = input.nextDouble();
- tmax[count] = input.nextDouble();
- count++;
- }
- System.out.println(arrayAvg(prcp));
- System.out.println(arrayAvg(snow));
- System.out.println(arrayAvg(snwd));
- System.out.println(arrayAvg(tmin));
- System.out.println(arrayAvg(tmax));
- }
- public static void process(Scanner input){
- while(input.hasNext()){
- String station = input.next();
- while(input.hasNextInt()){
- String date = input.next();
- while(input.hasNextInt()){
- int prcp = input.nextInt();
- while(input.hasNextInt()){
- int snow = input.nextInt();
- while(input.hasNextInt()){
- int snwd = input.nextInt();
- while(input.hasNextInt()){
- int tmin = input.nextInt();
- while(input.hasNextInt()){
- int tmax = input.nextInt();
- }
- }
- }
- }
- }
- }
- }
- }
- public static double arrayAvg(double array[]){
- int count = 0;
- double sum = 0;
- for(int i = 0; i < array.length; i++){
- count++;
- if(array[i] != 393.7){
- sum += array[i];
- }
- }
- return sum/count;
- }
- }
- public class MaainActivity extends Activity {
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- // Get the view from activity_main.xml
- setContentView(R.layout.activity_main);
- }
- }
- public class MainActivity extends Activity {
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- // Get the view from activity_main.xml
- setContentView(R.layout.activity_main);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement