0

For my beginner Java class I am writing a program that will read data from inData.txt and write output to the file outData.txt.

I have 5 errors that all say a symbol cannot be found but I'm not sure what exactly it's talking about or what is wrong.

The error:

E:\Java\Exercises\Chapter3\Ch3_PrExercise1.java:16: error: cannot find symbol
                num1 = inData.nextInt();
                             ^
  symbol:   method nextInt()
  location: variable inData of type String
E:\Java\Exercises\Chapter3\Ch3_PrExercise1.java:17: error: cannot find symbol
                num2 = inData.nextInt();
                             ^
  symbol:   method nextInt()
  location: variable inData of type String
E:\Java\Exercises\Chapter3\Ch3_PrExercise1.java:18: error: cannot find symbol
                str = inData.next();
                            ^
  symbol:   method next()
  location: variable inData of type String
E:\Java\Exercises\Chapter3\Ch3_PrExercise1.java:19: error: cannot find symbol
                num3 = inData.nextInt();
                             ^
  symbol:   method nextInt()
  location: variable inData of type String
E:\Java\Exercises\Chapter3\Ch3_PrExercise1.java:20: error: cannot find symbol
                num4 = inData.nextInt();

My code:

import java.io.*;
import java.util.*;
class Ch3_PrExercise1
    {
        public static void main(String args[] )
            {
                // declaration
                Scanner console = new Scanner(System.in);
                int num1, num2;
                int num3, num4;
                String str;
                String inData;

                // input
                Scanner inFile = new Scanner(new FileReader("inData.txt"));
                num1 = inData.nextInt();
                num2 = inData.nextInt();
                str = inData.next();
                num3 = inData.nextInt();
                num4 = inData.nextInt();
                inFile.close();

                // process
                int sum = (num1 + num2); // add numbers from line 1
                int product = (num3 * num4); // multiply numbers from line 3

                // output
                PrintWriter outFile = new PrintWriter("Outdata.txt");
                outFile.println( "The sum of (+ num1) and (+ num2) = + sum");
                outFile.println( "The character that comes after (+ str) in the unicode set is (+ <=)");
                outFile.println( "The product of (+ num3) and (+ num4) = + product");
                outFile.close();
            }
    }

Thanks for the help in advance! :)

1
Contributor
1
Reply
7
Views
3 Years
Discussion Span
Last Post by TheAustinG
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.