438,034 Members | 819 Online Need help? Post your question and get tips & solutions from a community of 438,034 IT Pros & Developers. It's quick & easy.

# Why is option #3 caught in a loop - I'm lost

 P: 23 import java.io.*; import java.util.*; public class Chunk { public static void main (String[] args) throws IOException { BufferedReader inFile = new BufferedReader(new FileReader("C:\\Chunk.dat")); PrintWriter Outfile = new PrintWriter(new FileWriter("C:\\Chunk.out")); BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in)); int firstNum, secondNum; int sumEven = 0; int sumSquareOdd = 0; char chCounter; int counter; int start; System.out.println("Enter two numbers."); System.out.println("First number must be less than or equal to " + "the second number you enter"); System.out.print("Enter the first number: "); System.out.flush(); firstNum = Integer.parseInt(stdin.readLine()); System.out.println(); System.out.print("Enter the second number: "); System.out.flush(); secondNum = Integer.parseInt(stdin.readLine()); System.out.println(); //Option #1 while(firstNum % 2 == 0) start = firstNum + 1; start = firstNum; Outfile.println("Odd integers between " + firstNum + " and " + secondNum + " are: "); for(counter = start; counter <= secondNum; counter = counter + 2) Outfile.print(counter + " "); Outfile.println(); //Option #2 while(firstNum % 2 == 0) start = firstNum; start = firstNum + 1; for(counter = start; counter <= secondNum; counter = counter + 2) sumEven = sumEven + counter; Outfile.println("Sum of even integers between " + firstNum + " and " + secondNum + " = " + sumEven); //Option #3 while(firstNum % 2 == 0); start = firstNum +1; Outfile.println("Number\t\tSquare of Number"); for(counter = start; counter <= secondNum; counter = counter) Outfile.println(counter + "\t\t" + counter * counter); Outfile.println(); //Part d while(firstNum % 2 == 0) start = firstNum + 1; start = firstNum; for(counter = start; counter <= secondNum; counter = counter + 2) sumSquareOdd = sumSquareOdd + counter * counter; Outfile.println("Sum of the squares of odd integers between " + firstNum + " and " + secondNum + " = " + sumSquareOdd); inFile.close(); Outfile.close(); } } Dec 8 '06 #1 