Illegal Start of Expression with Method












-5














So I am trying to open/close/reopen/read and array into a 1 dimensional array and a 2 dimensional array.



public class Assigntment2Condensed
{
public static void main (String args) throws IOException
{

//Creating the menu options

System.out.println("nnPlease choose an option belown"
+ "tA. Read Datan"
+ "tB. Modify Datan"
+ "tC. Clear Datan"
+ "tD. Display Datan"
+ "tE. Save Data to a filen"
+ "tF. Quit");
System.out.print("n=> ");
//WHAT I NEED: While loop and a nested If statement

//getting user input:: can create a method
String input = keyboard.nextLine();
input = input.toUpperCase(); //what the user inputs will be made to an upper case char
char charInput = input.charAt(0); //gets the character in the 0 position

//main methods
int originalMap = getMap(new Scanner(new File("map.dat"))); //reads data into the array :: Menu Option A
getShowArray(originalMap); //passing contents of original map into the method :: Menu Option D
getWriteArray(modifiedMap); //method created to write the contents of the modified map to a file. :: Menu Option B

// Method classes
//Read in array from file to a two dimen. array. returns array Map. :: Menu Option A
public static int getMap(Scanner file)
{
int index = 0;
String map;

Scanner keyboard = new Scanner(System.in);

System.out.println("nnOpening 'map.dat' file and adding elements to the array....n");

//open the file
File file = new File("map.dat");

Scanner openFile = new Scanner(file); //reads in the file into the openFile instance

//read the file contents
while(openFile.hasNext())
{
map = openFile.nextLine();

//System.out.println(map);
index++;

}
openFile.close();

//read contents into an array

File map2 = new File("map.dat");
Scanner openFile2 = new Scanner(map2);

int numArray = new int[index]; //creates Array
for(int i = 0; i < numArray.length; i++)
{
numArray[i] = openFile2.nextInt();
//System.out.print(numArray[i] + " " );

}



//-=-===-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-==-=
int rows = file.nextInt();
int columns = file.nextInt();

int map = new int[rows][columns];

for(int i = 0; i < rows; i++)
{
for(int j = 0; j < columns; j++)
{
map[i][j] = file.nextInt();
System.out.print(map[i][j] + " ");
}
System.out.println("");
}

file.close();

return map;
}

//displaying the array when called :: Menu Option D
private static void getShowArray(int originalMap)
{
for (int row = 0; row < originalMap.length; row++)
{
for(int col = 0; col < originalMap.length; col++)
System.out.print(originalMap[row][col] + " | ");
System.out.println();
}
}

//writing modifiedMap array to a txt file :: Menu Option B
public static void getWriteArray(int modifiedMap)
{
dataInputStream inputFile = new DataInputStream(new fileInputStream("map.dat"));
System.out.println("nWriting to the 'map.dat' file...");

//write to binary file
for (int i = 0; i < modifiedMap.length; i++)
outputFile.writeInt(modifiedMap[i]);

//close file
outputFile.close();
System.out.println("Done.");
}


}


I am getting the error:



Assigntment2Condensed.java:30: error: illegal start of expression
public static int getMap(Scanner file)
^
Assigntment2Condensed.java:30: error: illegal start of expression
public static int getMap(Scanner file)
^
Assigntment2Condensed.java:30: error: ';' expected
public static int getMap(Scanner file)
^
Assigntment2Condensed.java:30: error: illegal start of expression
public static int getMap(Scanner file)
^
Assigntment2Condensed.java:30: error: ';' expected
public static int getMap(Scanner file)
^
Assigntment2Condensed.java:30: error: illegal start of expression
public static int getMap(Scanner file)
^
Assigntment2Condensed.java:30: error: ';' expected
public static int getMap(Scanner file)
^
Assigntment2Condensed.java:30: error: ')' expected
public static int getMap(Scanner file)
^
Assigntment2Condensed.java:30: error: illegal start of expression
public static int getMap(Scanner file)
^
Assigntment2Condensed.java:30: error: ';' expected
public static int getMap(Scanner file)
^
10 errors


The "=-=-=-=-=-=-=-=-=-=-=-=-" is an indication of that the code prior to that line was previously outside of that method and anything below that was already working in that method. I need to create a menu option so when they click A the file is read into the program.










share|improve this question


















  • 3




    Please do not dump your whole code like this onto Stack Overflow... Read the help center and Minimal, Complete, and Verifiable example. For starters, you're missing a curly brace to end the main method.
    – Tunaki
    Sep 10 '16 at 20:51


















-5














So I am trying to open/close/reopen/read and array into a 1 dimensional array and a 2 dimensional array.



public class Assigntment2Condensed
{
public static void main (String args) throws IOException
{

//Creating the menu options

System.out.println("nnPlease choose an option belown"
+ "tA. Read Datan"
+ "tB. Modify Datan"
+ "tC. Clear Datan"
+ "tD. Display Datan"
+ "tE. Save Data to a filen"
+ "tF. Quit");
System.out.print("n=> ");
//WHAT I NEED: While loop and a nested If statement

//getting user input:: can create a method
String input = keyboard.nextLine();
input = input.toUpperCase(); //what the user inputs will be made to an upper case char
char charInput = input.charAt(0); //gets the character in the 0 position

//main methods
int originalMap = getMap(new Scanner(new File("map.dat"))); //reads data into the array :: Menu Option A
getShowArray(originalMap); //passing contents of original map into the method :: Menu Option D
getWriteArray(modifiedMap); //method created to write the contents of the modified map to a file. :: Menu Option B

// Method classes
//Read in array from file to a two dimen. array. returns array Map. :: Menu Option A
public static int getMap(Scanner file)
{
int index = 0;
String map;

Scanner keyboard = new Scanner(System.in);

System.out.println("nnOpening 'map.dat' file and adding elements to the array....n");

//open the file
File file = new File("map.dat");

Scanner openFile = new Scanner(file); //reads in the file into the openFile instance

//read the file contents
while(openFile.hasNext())
{
map = openFile.nextLine();

//System.out.println(map);
index++;

}
openFile.close();

//read contents into an array

File map2 = new File("map.dat");
Scanner openFile2 = new Scanner(map2);

int numArray = new int[index]; //creates Array
for(int i = 0; i < numArray.length; i++)
{
numArray[i] = openFile2.nextInt();
//System.out.print(numArray[i] + " " );

}



//-=-===-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-==-=
int rows = file.nextInt();
int columns = file.nextInt();

int map = new int[rows][columns];

for(int i = 0; i < rows; i++)
{
for(int j = 0; j < columns; j++)
{
map[i][j] = file.nextInt();
System.out.print(map[i][j] + " ");
}
System.out.println("");
}

file.close();

return map;
}

//displaying the array when called :: Menu Option D
private static void getShowArray(int originalMap)
{
for (int row = 0; row < originalMap.length; row++)
{
for(int col = 0; col < originalMap.length; col++)
System.out.print(originalMap[row][col] + " | ");
System.out.println();
}
}

//writing modifiedMap array to a txt file :: Menu Option B
public static void getWriteArray(int modifiedMap)
{
dataInputStream inputFile = new DataInputStream(new fileInputStream("map.dat"));
System.out.println("nWriting to the 'map.dat' file...");

//write to binary file
for (int i = 0; i < modifiedMap.length; i++)
outputFile.writeInt(modifiedMap[i]);

//close file
outputFile.close();
System.out.println("Done.");
}


}


I am getting the error:



Assigntment2Condensed.java:30: error: illegal start of expression
public static int getMap(Scanner file)
^
Assigntment2Condensed.java:30: error: illegal start of expression
public static int getMap(Scanner file)
^
Assigntment2Condensed.java:30: error: ';' expected
public static int getMap(Scanner file)
^
Assigntment2Condensed.java:30: error: illegal start of expression
public static int getMap(Scanner file)
^
Assigntment2Condensed.java:30: error: ';' expected
public static int getMap(Scanner file)
^
Assigntment2Condensed.java:30: error: illegal start of expression
public static int getMap(Scanner file)
^
Assigntment2Condensed.java:30: error: ';' expected
public static int getMap(Scanner file)
^
Assigntment2Condensed.java:30: error: ')' expected
public static int getMap(Scanner file)
^
Assigntment2Condensed.java:30: error: illegal start of expression
public static int getMap(Scanner file)
^
Assigntment2Condensed.java:30: error: ';' expected
public static int getMap(Scanner file)
^
10 errors


The "=-=-=-=-=-=-=-=-=-=-=-=-" is an indication of that the code prior to that line was previously outside of that method and anything below that was already working in that method. I need to create a menu option so when they click A the file is read into the program.










share|improve this question


















  • 3




    Please do not dump your whole code like this onto Stack Overflow... Read the help center and Minimal, Complete, and Verifiable example. For starters, you're missing a curly brace to end the main method.
    – Tunaki
    Sep 10 '16 at 20:51
















-5












-5








-5







So I am trying to open/close/reopen/read and array into a 1 dimensional array and a 2 dimensional array.



public class Assigntment2Condensed
{
public static void main (String args) throws IOException
{

//Creating the menu options

System.out.println("nnPlease choose an option belown"
+ "tA. Read Datan"
+ "tB. Modify Datan"
+ "tC. Clear Datan"
+ "tD. Display Datan"
+ "tE. Save Data to a filen"
+ "tF. Quit");
System.out.print("n=> ");
//WHAT I NEED: While loop and a nested If statement

//getting user input:: can create a method
String input = keyboard.nextLine();
input = input.toUpperCase(); //what the user inputs will be made to an upper case char
char charInput = input.charAt(0); //gets the character in the 0 position

//main methods
int originalMap = getMap(new Scanner(new File("map.dat"))); //reads data into the array :: Menu Option A
getShowArray(originalMap); //passing contents of original map into the method :: Menu Option D
getWriteArray(modifiedMap); //method created to write the contents of the modified map to a file. :: Menu Option B

// Method classes
//Read in array from file to a two dimen. array. returns array Map. :: Menu Option A
public static int getMap(Scanner file)
{
int index = 0;
String map;

Scanner keyboard = new Scanner(System.in);

System.out.println("nnOpening 'map.dat' file and adding elements to the array....n");

//open the file
File file = new File("map.dat");

Scanner openFile = new Scanner(file); //reads in the file into the openFile instance

//read the file contents
while(openFile.hasNext())
{
map = openFile.nextLine();

//System.out.println(map);
index++;

}
openFile.close();

//read contents into an array

File map2 = new File("map.dat");
Scanner openFile2 = new Scanner(map2);

int numArray = new int[index]; //creates Array
for(int i = 0; i < numArray.length; i++)
{
numArray[i] = openFile2.nextInt();
//System.out.print(numArray[i] + " " );

}



//-=-===-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-==-=
int rows = file.nextInt();
int columns = file.nextInt();

int map = new int[rows][columns];

for(int i = 0; i < rows; i++)
{
for(int j = 0; j < columns; j++)
{
map[i][j] = file.nextInt();
System.out.print(map[i][j] + " ");
}
System.out.println("");
}

file.close();

return map;
}

//displaying the array when called :: Menu Option D
private static void getShowArray(int originalMap)
{
for (int row = 0; row < originalMap.length; row++)
{
for(int col = 0; col < originalMap.length; col++)
System.out.print(originalMap[row][col] + " | ");
System.out.println();
}
}

//writing modifiedMap array to a txt file :: Menu Option B
public static void getWriteArray(int modifiedMap)
{
dataInputStream inputFile = new DataInputStream(new fileInputStream("map.dat"));
System.out.println("nWriting to the 'map.dat' file...");

//write to binary file
for (int i = 0; i < modifiedMap.length; i++)
outputFile.writeInt(modifiedMap[i]);

//close file
outputFile.close();
System.out.println("Done.");
}


}


I am getting the error:



Assigntment2Condensed.java:30: error: illegal start of expression
public static int getMap(Scanner file)
^
Assigntment2Condensed.java:30: error: illegal start of expression
public static int getMap(Scanner file)
^
Assigntment2Condensed.java:30: error: ';' expected
public static int getMap(Scanner file)
^
Assigntment2Condensed.java:30: error: illegal start of expression
public static int getMap(Scanner file)
^
Assigntment2Condensed.java:30: error: ';' expected
public static int getMap(Scanner file)
^
Assigntment2Condensed.java:30: error: illegal start of expression
public static int getMap(Scanner file)
^
Assigntment2Condensed.java:30: error: ';' expected
public static int getMap(Scanner file)
^
Assigntment2Condensed.java:30: error: ')' expected
public static int getMap(Scanner file)
^
Assigntment2Condensed.java:30: error: illegal start of expression
public static int getMap(Scanner file)
^
Assigntment2Condensed.java:30: error: ';' expected
public static int getMap(Scanner file)
^
10 errors


The "=-=-=-=-=-=-=-=-=-=-=-=-" is an indication of that the code prior to that line was previously outside of that method and anything below that was already working in that method. I need to create a menu option so when they click A the file is read into the program.










share|improve this question













So I am trying to open/close/reopen/read and array into a 1 dimensional array and a 2 dimensional array.



public class Assigntment2Condensed
{
public static void main (String args) throws IOException
{

//Creating the menu options

System.out.println("nnPlease choose an option belown"
+ "tA. Read Datan"
+ "tB. Modify Datan"
+ "tC. Clear Datan"
+ "tD. Display Datan"
+ "tE. Save Data to a filen"
+ "tF. Quit");
System.out.print("n=> ");
//WHAT I NEED: While loop and a nested If statement

//getting user input:: can create a method
String input = keyboard.nextLine();
input = input.toUpperCase(); //what the user inputs will be made to an upper case char
char charInput = input.charAt(0); //gets the character in the 0 position

//main methods
int originalMap = getMap(new Scanner(new File("map.dat"))); //reads data into the array :: Menu Option A
getShowArray(originalMap); //passing contents of original map into the method :: Menu Option D
getWriteArray(modifiedMap); //method created to write the contents of the modified map to a file. :: Menu Option B

// Method classes
//Read in array from file to a two dimen. array. returns array Map. :: Menu Option A
public static int getMap(Scanner file)
{
int index = 0;
String map;

Scanner keyboard = new Scanner(System.in);

System.out.println("nnOpening 'map.dat' file and adding elements to the array....n");

//open the file
File file = new File("map.dat");

Scanner openFile = new Scanner(file); //reads in the file into the openFile instance

//read the file contents
while(openFile.hasNext())
{
map = openFile.nextLine();

//System.out.println(map);
index++;

}
openFile.close();

//read contents into an array

File map2 = new File("map.dat");
Scanner openFile2 = new Scanner(map2);

int numArray = new int[index]; //creates Array
for(int i = 0; i < numArray.length; i++)
{
numArray[i] = openFile2.nextInt();
//System.out.print(numArray[i] + " " );

}



//-=-===-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-==-=
int rows = file.nextInt();
int columns = file.nextInt();

int map = new int[rows][columns];

for(int i = 0; i < rows; i++)
{
for(int j = 0; j < columns; j++)
{
map[i][j] = file.nextInt();
System.out.print(map[i][j] + " ");
}
System.out.println("");
}

file.close();

return map;
}

//displaying the array when called :: Menu Option D
private static void getShowArray(int originalMap)
{
for (int row = 0; row < originalMap.length; row++)
{
for(int col = 0; col < originalMap.length; col++)
System.out.print(originalMap[row][col] + " | ");
System.out.println();
}
}

//writing modifiedMap array to a txt file :: Menu Option B
public static void getWriteArray(int modifiedMap)
{
dataInputStream inputFile = new DataInputStream(new fileInputStream("map.dat"));
System.out.println("nWriting to the 'map.dat' file...");

//write to binary file
for (int i = 0; i < modifiedMap.length; i++)
outputFile.writeInt(modifiedMap[i]);

//close file
outputFile.close();
System.out.println("Done.");
}


}


I am getting the error:



Assigntment2Condensed.java:30: error: illegal start of expression
public static int getMap(Scanner file)
^
Assigntment2Condensed.java:30: error: illegal start of expression
public static int getMap(Scanner file)
^
Assigntment2Condensed.java:30: error: ';' expected
public static int getMap(Scanner file)
^
Assigntment2Condensed.java:30: error: illegal start of expression
public static int getMap(Scanner file)
^
Assigntment2Condensed.java:30: error: ';' expected
public static int getMap(Scanner file)
^
Assigntment2Condensed.java:30: error: illegal start of expression
public static int getMap(Scanner file)
^
Assigntment2Condensed.java:30: error: ';' expected
public static int getMap(Scanner file)
^
Assigntment2Condensed.java:30: error: ')' expected
public static int getMap(Scanner file)
^
Assigntment2Condensed.java:30: error: illegal start of expression
public static int getMap(Scanner file)
^
Assigntment2Condensed.java:30: error: ';' expected
public static int getMap(Scanner file)
^
10 errors


The "=-=-=-=-=-=-=-=-=-=-=-=-" is an indication of that the code prior to that line was previously outside of that method and anything below that was already working in that method. I need to create a menu option so when they click A the file is read into the program.







java arrays






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Sep 10 '16 at 20:49









Chris Zog

33




33








  • 3




    Please do not dump your whole code like this onto Stack Overflow... Read the help center and Minimal, Complete, and Verifiable example. For starters, you're missing a curly brace to end the main method.
    – Tunaki
    Sep 10 '16 at 20:51
















  • 3




    Please do not dump your whole code like this onto Stack Overflow... Read the help center and Minimal, Complete, and Verifiable example. For starters, you're missing a curly brace to end the main method.
    – Tunaki
    Sep 10 '16 at 20:51










3




3




Please do not dump your whole code like this onto Stack Overflow... Read the help center and Minimal, Complete, and Verifiable example. For starters, you're missing a curly brace to end the main method.
– Tunaki
Sep 10 '16 at 20:51






Please do not dump your whole code like this onto Stack Overflow... Read the help center and Minimal, Complete, and Verifiable example. For starters, you're missing a curly brace to end the main method.
– Tunaki
Sep 10 '16 at 20:51














1 Answer
1






active

oldest

votes


















2














You can't have a method inside a method. The compiler thinks that public static int getMap(Scanner file) is inside your main method, and it's probably not what you're after.






share|improve this answer





















    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f39430464%2fillegal-start-of-expression-with-method%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    2














    You can't have a method inside a method. The compiler thinks that public static int getMap(Scanner file) is inside your main method, and it's probably not what you're after.






    share|improve this answer


























      2














      You can't have a method inside a method. The compiler thinks that public static int getMap(Scanner file) is inside your main method, and it's probably not what you're after.






      share|improve this answer
























        2












        2








        2






        You can't have a method inside a method. The compiler thinks that public static int getMap(Scanner file) is inside your main method, and it's probably not what you're after.






        share|improve this answer












        You can't have a method inside a method. The compiler thinks that public static int getMap(Scanner file) is inside your main method, and it's probably not what you're after.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Sep 10 '16 at 21:01









        Joe C

        10.7k62341




        10.7k62341






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.





            Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


            Please pay close attention to the following guidance:


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f39430464%2fillegal-start-of-expression-with-method%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Xamarin.iOS Cant Deploy on Iphone

            Glorious Revolution

            Dulmage-Mendelsohn matrix decomposition in Python