I'm writing a program that took a matrix and put each column into its own int[]. Now for the part I'm struggling with. I need to tally up the numbers that are >= 4. Here's my code:
I get nothing for my output. I have been at this chipping away since 1:30 P.M and it is now 1:30 A.M. If someone could take a look and point me in the right direction that would be grand.
Code:
import java.io.*;
import java.util.*;
public class SunMoon {
public static void main(String[] args) throws FileNotFoundException {
// TODO Auto-generated method stub
File file = new File("Portland.txt");
try {
Scanner console = new Scanner(file);
while (console.hasNextLine()) {
Scanner lineScanner = new Scanner(console.nextLine());
lineScanner.useDelimiter("[/,\\s]+");
String year = lineScanner.next();
int[] years=new int[year.length()];
for(int i=0;i<year.length();i++){
years[i]=Integer.parseInt(year);
break;
}
String month=lineScanner.next();
int[] months=new int[month.length()];
for(int i=0;i<month.length();i++){
months[i]=Integer.parseInt(month);
}
String day=lineScanner.next();
int[] days=new int[day.length()];
for(int i=0;i<day.length();i++){
days[i]=Integer.parseInt(day);
}
String tmin=lineScanner.next();
int[] tMin=new int[tmin.length()];
for(int i=0;i<tmin.length();i++){
tMin[i]=Integer.parseInt(tmin);
}
String tmax=lineScanner.next();
int[] tMax=new int[tmax.length()];
for(int i=0;i<tmax.length();i++){
tMax[i]=Integer.parseInt(tmax);
}
String prcp=lineScanner.next();
int[] pRCP=new int[prcp.length()];
for(int i=0;i<prcp.length();i++){
pRCP[i]=Integer.parseInt(prcp);
}
String snow=lineScanner.next();
int[] sNOW=new int[snow.length()];
for(int i=0;i<snow.length();i++){
sNOW[i]=Integer.parseInt(snow);
}
String snwd=lineScanner.next();
int[] sNWD=new int[snwd.length()];
for(int i=0;i<snwd.length();i++){
sNWD[i]=Integer.parseInt(snwd);
}
}
console.close();
}
catch (FileNotFoundException e) {
e.printStackTrace();
}
}
public static void skiableDays(int[] sNWD) {
int skiable=0;
for (int i = 0; i < sNWD.length; i++) {
if (sNWD[i] >= 4){
skiable++;
}
}System.out.println("There were "+skiable+" skiable days.");
}
}
Comment