Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    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 23:07 Go to next message
john hanly is currently offline john hanlyFriend
Messages: 2
Registered: August 2020
Junior Member
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 05:21 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33136
Registered: July 2009
Senior Member
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?

Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Eclipse changes my Code [message #1830811 is a reply to message #1830791] Tue, 04 August 2020 15:08 Go to previous messageGo to next message
john hanly is currently offline john hanlyFriend
Messages: 2
Registered: August 2020
Junior Member
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] Wed, 05 August 2020 02:15 Go to previous message
Nitin Dahyabhai is currently offline Nitin DahyabhaiFriend
Messages: 4435
Registered: July 2009
Senior Member

And you're saying that the act of running that code is rewriting it?

_
Nitin Dahyabhai
Eclipse Web Tools Platform
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: Fri Apr 19 04:38:13 GMT 2024

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

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

Back to the top