i want to use a for loop in a function but error occur.. why??
public double weight( double d)
{
for(int i=0;i<5;i++)
{ d /= 24;}
return d;
}
A quick diagnostic tied to the existing posts: reported a compile error inside a loop and flagged a type concern. The loop construct itself is rarely the root cause. More often the compiler points to a syntax problem introduced by stray characters or misplaced code (for example, HTML emphasis tags injected by a forum editor), unbalanced braces, a missing semicolon, or a method placed outside any class. If the intent was to iterate over multiple values, a primitive value will not behave like an array or list — that distinction is what was referring to.
Practical checks that resolve this class of error most of the time:
Reference material: the Java tutorials on operators and on arrays explain compound assignment and array usage in detail (Java Operators, Java Arrays). Removing any stray markup or correcting type/placement typically clears the error.
Jump to Post— javaAddict 900'd' is a double, not an array.
'd' is a double, not an array.
error in for loop.. this one { d /= 24;}
so how do i solve it??
'd' is not an array.
Just study some basic java on how to declare variables and arrays.
ok2..thanks..:)
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.