Question #14899
Write a program that outputs n numbers from two sequences turn by turn and each number in its own line (2*n numbers in total). The first sequence is a, a+2, a+4, ... and the second b, b+5, b+10, ... Variables n, a and b have already been declared and should be used in your program code. For example if a = 4 and b = 7, the program should output:
4
7
6
12
8
17
...
1
Expert's answer
2017-01-25T08:51:20-0500
import java.util.InputMismatchException;import java.util.Scanner;public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); int a = 0, b = 0, n = 0; int k; System.out.println("Enter n, a, b separated by a space: "); try { n = in.nextInt(); a = in.nextInt(); b = in.nextInt(); } catch (InputMismatchException e) { System.out.println("Some from what you type - not a number ))) Restart the program"); return; } k = 2 * n; for (int i = 0, j = 0; i < k; i+=2, j+=5) { System.out.println(a+i); System.out.println(b+j);    }  }}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!
LATEST TUTORIALS
APPROVED BY CLIENTS