d2jsp
Log InRegister
d2jsp Forums > Off-Topic > Computers & IT > Programming & Development > Java Help! > Separating Numbers
Prev12
Add Reply New Topic New Poll
Member
Posts: 1,995
Joined: Jun 28 2006
Gold: 7.41
Apr 16 2014 03:02pm
Wrap the statements underneath the for in braces to establish a block. Otherwise you are only executing the first statement as part of the loop
Member
Posts: 2,431
Joined: Dec 27 2009
Gold: 1,356.00
Apr 16 2014 03:06pm
Quote (Minkomonster @ Apr 16 2014 02:02pm)
Wrap the statements underneath the for in braces to establish a block. Otherwise you are only executing the first statement as part of the loop


what? can you put a code in?
Member
Posts: 2,431
Joined: Dec 27 2009
Gold: 1,356.00
Apr 16 2014 03:15pm
Quote (Minkomonster @ Apr 16 2014 02:02pm)
Wrap the statements underneath the for in braces to establish a block. Otherwise you are only executing the first statement as part of the loop


the error code is just saying "1 invalid variable deceleration"
Member
Posts: 1,995
Joined: Jun 28 2006
Gold: 7.41
Apr 16 2014 05:32pm
Quote (GrafEmpire @ Apr 16 2014 04:15pm)
the error code is just saying "1 invalid variable deceleration"


Code
public class seperating {

/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
int i;

String a = "12345";
String b = "";

//why are you trying to initialize a variable named 1?
//and why did you not wrap the statements underneath this for in braces? {}
for ( int 1 = 0; i < a.length(); i++)
b += a.charAt( i );

//1 + 1 eh?
if ( 1 + 1 <= a.length( ) )
b += " ";


}

}



Code
public class seperating {
public static void main(String[] args) {

String a = "12345";
String b = "";

for ( int i = 0; i < a.length(); i++)
{
b += a.charAt( i );
if ( i + 1 <= a.length( ) )
b += " ";
}

}

}
Member
Posts: 1,241
Joined: Jun 25 2011
Gold: Locked
Apr 17 2014 04:38am
Quote (GrafEmpire @ Apr 16 2014 10:06pm)
what? can you put a code in?


Something tells me you've slept some of your Java classes :rofl:
Member
Posts: 2,431
Joined: Dec 27 2009
Gold: 1,356.00
Apr 17 2014 10:40am
Quote (m0hawk @ Apr 17 2014 03:38am)
Something tells me you've slept some of your Java classes  :rofl:


only 2
Member
Posts: 1,995
Joined: Jun 28 2006
Gold: 7.41
Apr 17 2014 10:48am
2 lectures or 2 whole classes?
Member
Posts: 2,431
Joined: Dec 27 2009
Gold: 1,356.00
Apr 17 2014 10:49am
Quote (Minkomonster @ Apr 17 2014 09:48am)
2 lectures or 2 whole classes?


we dont have anything lectures we have a book and we are supposed to do stuff from the book.
Member
Posts: 7,240
Joined: Jun 6 2006
Gold: Locked
Trader: Scammer
Apr 17 2014 04:52pm
Quote (GrafEmpire @ Apr 16 2014 05:06pm)
what? can you put a code in?

You need to put braces around your for loops and while loops for the entire block of code unless it's only one statement.
I PMed you the notes I was taught Java with. Enjoy.
Go Back To Programming & Development Topic List
Prev12
Add Reply New Topic New Poll