Ask your own question, for FREE!
Computer Science 20 Online
MadamMystery:

Write a program in Java to print the series 1 3 5 11 19... Upto 10 terms Don't type anything useless :(

minustempo:

Sorry can you explain the sequence 1 3 5 11 19 doesn't seem to have any pattern to it

toga:

Here's the Java code to print the series 1 3 5 11 19... up to 10 terms: ``` public class Main { public static void main(String[] args) { int n = 10; int a = 1, b = 3, c = 5; System.out.print(a + " " + b + " " + c + " "); for(int i = 4; i <= n; i++) { int d = (i % 2 == 0) ? (c + 6) : (c + 2); System.out.print(d + " "); a = b; b = c; c = d; } } } ``` This code uses a loop to print out the first 10 terms of the series. The first three terms are printed outside of the loop, and then the loop calculates and prints the remaining terms. The calculation of each new term depends on whether the term is even or odd.

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!