# Newbie needs help with program assignment

• 02-25-2012, 05:09 PM
pitmanr2003
Newbie needs help with program assignment
I have to write a program that reads from a file. The file has 15 sets of numbers per line and 10 lines. I then have to output the total of all numbers in each line as well as sum of all even numbers and sum of all odd numbers. Also have to output how many zeros in each line. I have the program totaling the lines, and know the if statement to use to find even, odd, as well as zeros. the issue is that i assigned each number in a row to 15 different variables and for the life of me cant figure out how to use if else statement to seperate the even, odd and zeros. I got so frustrated that i did 15 different if else statements, but got borked results after first line. I hope i havent confused you all worse than i am.
here is my code. it is in the building stage so ignore some of the variables and comments. the output is perfect as for string minipulation that the teacher wants, just need to get the logic right

Code:

```//******************************************************************** //  Lincoln.java      Java Foundations // //  Demonstrates the basic structure of a Java application. //******************************************************************** import java.util.Scanner; import java.io.*; public class Numbers {   //-----------------------------------------------------------------   //  Prints a presidential quote.   //-----------------------------------------------------------------   public static void main (String[] args) throws IOException   {       int num1,num2,num3,num4,num5,num6,num7,num8,num9,num10,num11,num12,num13,num14,num15;           int total, count, even, odd, zeros, countz, notTab;       String str;       Scanner fileScan, lineScan; fileScan = new Scanner (new File("Numbers.txt")); count = 0; countz = 0;       while (fileScan.hasNext())       {                   even = 0;                     odd = 0;                   str = fileScan.nextLine();                   lineScan = new Scanner(str);                   lineScan.useDelimiter(" ");                   num1 = lineScan.nextInt();                   num2 = lineScan.nextInt();                   num3 = lineScan.nextInt();                   num4 = lineScan.nextInt();                   num5 = lineScan.nextInt();                   num6 = lineScan.nextInt();                   num7 = lineScan.nextInt();                   num8 = lineScan.nextInt();                   num9 = lineScan.nextInt();                   num10 = lineScan.nextInt();                   num11 = lineScan.nextInt();                   num12 = lineScan.nextInt();                   num13 = lineScan.nextInt();                   num14 = lineScan.nextInt();                   num15 = lineScan.nextInt();                 total = num1 + num2 + num3 + num4 + num5 + num6 + num7 + num8 +                 num9 + num10 + num11 + num12 + num13 + num14 + num15;                 count++;                 {                 if (odd > 9 || odd < 0)                         System.out.println("Record: " + count + "\tTotal: " + total + "\tEvens: " +                     even + "\tOdds: " + odd + "\tZeros: " + countz);                 else                     System.out.println("Record: " + count + "\tTotal: " + total + "\tEvens: " +                     even + "\tOdds: " + odd + "\t\tZeros: " + countz);                 }         }   } }```
• 02-25-2012, 06:17 PM
Norm
Re: Newbie needs help with program assignment