Question #35714

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
...
Do not write main method. Just the necessary code lines


import java.util.Random;

public class Test{
public static void main(String[] args){
Random r = new Random();
r.setSeed(Long.parseLong(args[0]));
int n = r.nextInt(100) + 100;
int a = r.nextInt(20) + 10;
int b = r.nextInt(20) + 10;

Expert's answer

import java.util.Random;
public class Test{
    public static void main(String[] args){
        Random r = new Random();
        r.setSeed(Long.parseLong(args[0]));
        int n = r.nextInt(100) + 100;
        int a = r.nextInt(20) + 10;
        int b = r.nextInt(20) + 10;
        int astep=2;
        int bstep=5;
        for (int i=0; i<n; i++){
            System.out.println((a+=astep)+"\n"+(b+=bstep));
        }
    }
}

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!

LATEST TUTORIALS
APPROVED BY CLIENTS