XML, Perl, Python, and other languages can be discussed here, even if it isn't PHP (We might forgive you).
Moderator: General Moderators
Obadiah
Forum Regular
Posts: 580 Joined: Mon Jul 31, 2006 9:13 am
Location: Ashland, KY
Contact:
Post
by Obadiah » Tue Oct 21, 2008 1:36 pm
so im trying a go at java again and in school we never had to do this but surfing online i saw that its possible with a for each but not specifically the way i need it to work
heres what i think i know...emphasis on the think;
i cant just do this however i wish i could
Code: Select all
for(int i = 7.56; i < 56; i += 1.02){
System.out.println(i);}
there has got to be an array from what the internet tells me however no good examples in my book
help please devnet, tag ur in
andyhoneycutt
Forum Contributor
Posts: 468 Joined: Wed Aug 27, 2008 10:02 am
Location: Idaho Falls
Post
by andyhoneycutt » Tue Oct 21, 2008 3:59 pm
have you tried using a float instead of an integer for your loop?
Obadiah
Forum Regular
Posts: 580 Joined: Mon Jul 31, 2006 9:13 am
Location: Ashland, KY
Contact:
Post
by Obadiah » Tue Oct 21, 2008 5:00 pm
just tried using a float however i think i used it the wrong way
i got as a build error....
C:\Documents and Settings\administrator\My Documents\JCreator LE\MyProjects\stocks.java:12: possible loss of precision
found : double
required: float
for(float i = 7.56; i < 56; i += 1.02){
}
funny enough it processed the code and gave me an output of
List average is 25.4
*edited
using double throws a very bad error....not sure why
andyhoneycutt
Forum Contributor
Posts: 468 Joined: Wed Aug 27, 2008 10:02 am
Location: Idaho Falls
Post
by andyhoneycutt » Wed Oct 22, 2008 2:00 pm
Code: Select all
for(float i = 7.56; i < 56; i += 1.02){
}
Try:
Code: Select all
for( float i = 7.56[color=#FF0000]f[/color]; i < 56; i += 1.02 )
...
Obadiah
Forum Regular
Posts: 580 Joined: Mon Jul 31, 2006 9:13 am
Location: Ashland, KY
Contact:
Post
by Obadiah » Thu Oct 23, 2008 2:30 am
andyhoneycutt wrote: Code: Select all
for(float i = 7.56; i < 56; i += 1.02){
}
Try:
Code: Select all
for( float i = 7.56[color=#FF0000]f[/color]; i < 56; i += 1.02 )
...
i tried another method....i got results but its not working as it should
it adds the 1.02 to the 7.56 but it just does it one time, and it loops indefinately instead of 56 times and i cant figure out where i fouled it up
Code: Select all
class example {
public static void main(String[]args) {
double x,y;
for(x = 1; x < 56; x++){
x=7.56;
y = x + 1.02;
System.out.println(x);
}
}
}
well...at least i got progress this time....however howw do i get it to stop looping indefinately and why wont it keep adding the 1.02?
Obadiah
Forum Regular
Posts: 580 Joined: Mon Jul 31, 2006 9:13 am
Location: Ashland, KY
Contact:
Post
by Obadiah » Thu Oct 23, 2008 2:56 am
ok...i got the first part of my last two questions....because i set xto 56 and then tried to set x again to 7.56 and giving y its value....made y make the for loop run indefinately...now what?
Obadiah
Forum Regular
Posts: 580 Joined: Mon Jul 31, 2006 9:13 am
Location: Ashland, KY
Contact:
Post
by Obadiah » Sat Oct 25, 2008 10:37 pm
didnt want to bump this but its seriously kickin my butt....im open for any suggestions....anyone?
andyhoneycutt
Forum Contributor
Posts: 468 Joined: Wed Aug 27, 2008 10:02 am
Location: Idaho Falls
Post
by andyhoneycutt » Wed Nov 19, 2008 10:58 am
Obadiah wrote: i tried another method....i got results but its not working as it should
it adds the 1.02 to the 7.56 but it just does it one time, and it loops indefinately instead of 56 times and i cant figure out where i fouled it up
Code: Select all
class example {
public static void main(String[] args) {
[color=#BF0000]float[/color] x,y;
for([color=#BF0000]x = 1.00[/color]; x < [color=#BF0000]56.00[/color]; [color=#BF0000]x += 1.02[/color]){
System.out.println(x);
}
}
}
This does not work? Please post your new code
-Andy