Java Programming

JamesMCFC

Well-Known Member
Joined
14 Apr 2010
Messages
2,378
Location
Having a kick about with Silva in the clough.
Anyone know whats up with this code?


public class q16
{
public static void main(String[] args)
{
int count;
int index;
int sum;
int average;
count = 10;
index = sum = count + 5;
sum = count + index * 2;
average = count + sum + index / 5;

}
}

for some reason average is never being read?
 
JamesMCFC said:
Anyone know whats up with this code?


public class q16
{
public static void main(String[] args)
{
int count;
int index;
int sum;
int average;
count = 10;
index = sum = count + 5;
sum = count + index * 2;
average = count + sum + index / 5;

}
}

for some reason average is never being read?

Use a debugger..but my guess is that it bombs out without getting into the function or class.
 
Can anyone who has eclipse and good at Java know how to stop this code from producing an infinite loop?


public class loop {


public static void main(String[] args) {
// TODO Auto-generated method stub
int total = 0;
int count = 0;
while (count < 10)
{
System.out.print(count + "*");
total = total + count;
}
System.out.println(total);
}

}
 
JamesMCFC said:
Can anyone who has eclipse and good at Java know how to stop this code from producing an infinite loop?


public class loop {


public static void main(String[] args) {
// TODO Auto-generated method stub
int total = 0;
int count = 0;
while (count < 10)
{
System.out.print(count + "*");
total = total + count;
}
System.out.println(total);
}

}
You aren't incrementing count?
 

Don't have an account? Register now and see fewer ads!

SIGN UP
Back
Top
  AdBlock Detected
Bluemoon relies on advertising to pay our hosting fees. Please support the site by disabling your ad blocking software to help keep the forum sustainable. Thanks.