Pls help:) Write a program called Product1ToN to compute the product of integers 1 to 10 (i.e., 1×2×3×...×10). Try computing the product from 1 to 11, 1 to 12, 1 to 13 and 1 to 14. Write down the product obtained and explain the results
I am stuck with only the explanation part.
@TuringTest
@experimentX
where are you stuck? have you written any pseudocode? in what language are you working?
you say you are stuck only with the explanation...?
Java. ya. here is the code. public class Product1toN { public static void main(String[] args) { int N=10; int product=1; for(int i=1;i<=N;i++) { product*=i; } System.out.print("Product of numbers from 1 to "+N+" is "+product); } }
I'd say that depends on how you wrote your code
well it's poorly-worded, to be sure. "explain the results" could mean a lot of things. I guess i'd describe how your loop works in words.
Oh k.I thought we need to explain about the factorial.
that;s why I said it's poorly-worded... I don't know if you are translating this from another language or what, but if this is direct from the tectbook, that's lame. The literal "result" is that the series n! for 0<n<11 is printed to standard out, which is almost cerstainly your screen, in the format string you wrote in your system.out.print statement. I don't know java syntax at all btw, I can only gather from c++
haven't tested public class Test{ public static void main(String[] args){ System.out.println(fact(10)); } public static int fact(int n){ if(n>1) return fact(n-1)*n; else return 1 } }
*Test.fact(10)
there you go .. hate Java
My "explanation of the results" is that each iteration multiplies product, increments i, and sends the resulting print statement to standard out. I can't testify as to the correctness of your code as, again, I don't know java.
Actually I got this question from this website. http://www.ntu.edu.sg/home/ehchua/programming/java/J2a_BasicsExercises.html. I got the correct output when I executed my code. thank u so much for both of u for helping me out.:)
without recursion public class Test{ public static void main(String[] args){ System.out.println(Test.fact(2)); System.out.println(Test.fact(3)); System.out.println(Test.fact(4)); } public static int fact(int n){ int j=1; for(int i=1; i<=n; i++) j = j*i; return j; } }
how do you put code in OS?
I'd like to know that as well
`code`
`code code code code` multiline does not work :(
Latex is nt working for me. is t working for u all?
latex wasn't working from Windows 8 ... but i logged in using linux ... so it's fine.
oh k.:)
Is this question answered?
Aj princess code generates numbers between 1 and 10.
Like in place of 10 you can say n and take user input so then you can ask it to go till 11,12,13,14.
yeah I don't know java, but that print statement looks like it's in the wrong place. The question though, was about the "explanation of the results", so....?
Lol this is just basic java.If you knew C# or C language you could understand.
Join our real-time social learning platform and learn together with your friends!