Skip to main content



      Home
Home » Newcomers » Newcomers » Eclipse changes my Code(Eclipse keeps changing my java code to something different.)
Eclipse changes my Code [message #1830783] Mon, 03 August 2020 19:07 Go to next message
Eclipse UserFriend
I am teaching myself java by going thru the book Java and Eclipse for ComputerScience. I am working on an example in chapter five. I type in the code given in the book, but when I run it, certain lines and variables are changed by Eclipse. It appears the changed lines are easier to understand but it interferes with me following the example in the book. How do I stop Eclipse from changing my code?
Re: Eclipse changes my Code [message #1830791 is a reply to message #1830783] Tue, 04 August 2020 01:21 Go to previous messageGo to next message
Eclipse UserFriend
It's hard to guess specifically what changes you are seeing. Could you provide enough details such that someone else could reproduce the problem you describe?
Re: Eclipse changes my Code [message #1830811 is a reply to message #1830791] Tue, 04 August 2020 11:08 Go to previous messageGo to next message
Eclipse UserFriend
Yes, i have the following code directly from the book.

package array2d;

public class Array2D {

public static void main(String[] args) {
// TODO Auto-generated method stub

//Basic test
int [][] test1 = new int[4][5];

test1[0][0] = 5;
test1[1][3] = 3;

System.out.println("The row length is " + test1.length);
System.out.println("The colunm length is " + test1[0].length);

//Search using counters
int z = 0;
// int[][] test2 = { { 3, 2, 6, 5 }, { 2, 7, 8, 1 }, { 4, 2, 7, 2 } };
int[][] test2 = { { 3, 2, 6, 5 }, { 2, 7 }, { 4, 2, 7, 2 }, { 7, 9, 2, 1, 6, 5 } };

//Counter search
for (int[] element : test2) {
for (int y = 0; y < element.length; y++ )
{
if(element[y] == 2)
{
z++;
}
}
}

System.out.println("The number 2 was found " + z + " times");


//Enhanced for-loop search
z=0;
for (int x[] : test2)
{
for(int y : x)
{
if (y == 7)
{
z++;
}
}
}
System.out.println("The number 7 was found " + z + " times");

}
}

Under the comment Counter Search the following 4 lines have the word 'element' in them. The original lines after counter search were:

for ( int x = 0; x< test2.length; x++) {
for (int y = 0;y< test2[x].length; y++) {
if ( test2[x][y] == 2) {
z++;
}
}
{

i understand the added lines are a shorter way of doing the double loop but i need the original code to follow the book. If you replace the lines after Counter search with these lines you'll have the original code.

thanks

Re: Eclipse changes my Code [message #1830831 is a reply to message #1830811] Tue, 04 August 2020 22:15 Go to previous message
Eclipse UserFriend
And you're saying that the act of running that code is rewriting it?
Previous Topic:Jave Error message starting " Capella " program (Solved)
Next Topic:Hover not working when I am using reference instead of name in model
Goto Forum:
  


Current Time: Sun Jul 06 11:42:16 EDT 2025

Powered by FUDForum. Page generated in 0.09594 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top