excuse me, can somebody explain how this constructor work? thanks before
void tampil(){
for(i=0;i<=20;i++)
{
System.out.print(i+" ");
if(i%2==1)
{
System.out.print(i+" ");
}
}
}
Re: excuse me, can somebody explain how this constructor work? thanks before
Which statement are you asking about? What happens when the code is executed? The output will show you what the code does when it is executed?
The % 2 == 1 test could be used to determine if a number is odd
Re: excuse me, can somebody explain how this constructor work? thanks before
Quote:
Originally Posted by
Norm
Which statement are you asking about? What happens when the code is executed? The output will show you what the code does when it is executed?
The % 2 == 1 test could be used to determine if a number is odd
i mean how constructor for(i=0;i<=20;i++) can join with constructor if(i%2==1), how the process ? why can produce output 0 11 22 33 until 20?
Re: excuse me, can somebody explain how this constructor work? thanks before
Please post the output from when you execute the program.
Re: excuse me, can somebody explain how this constructor work? thanks before
Quote:
Originally Posted by
erdy_rezki
void tampil(){
for(i=0;i<=20;i++)
{
System.out.print(i+" ");
if(i%2==1)
{
System.out.print(i+" ");
}
}
}
Hello,
i initialize with 0 so first print 0 then
its comes next if statement it checks with i value
if its odd means it will give 1
otherwise 0
so only odd no's print twice...
Check with your output and keep rocking....
Re: excuse me, can somebody explain how this constructor work? thanks before
Quote:
Originally Posted by
Norm
Please post the output from when you execute the program.
the output is 0 11 2 33 4 55 6 77 8 99 10 11 11 12 13 13 14 15 15 16 17 17 18 19 19 20
Re: excuse me, can somebody explain how this constructor work? thanks before
Quote:
Originally Posted by
treacyjane
Hello,
i initialize with 0 so first print 0 then
its comes next if statement it checks with i value
if its odd means it will give 1
otherwise 0
so only odd no's print twice...
Check with your output and keep rocking....
oke thanks for your comment it really help