Question: import java.util.Scanner; public class Lab09{ public static void main(String[] args) { int num; Scanner in = new Scanner(System.in); System.out.print( Enter a number : ); num
import java.util.Scanner;
public class Lab09{
public static void main(String[] args) {
int num;
Scanner in = new Scanner(System.in);
System.out.print(" Enter a number : ");
num = in.nextInt();
for(int i = 1;i <= num;i++){
if(i % 2 != 0)
System.out.print(2*i+" ");
else
System.out.print(-(2*i-1)+" ");
}
System.out.println();
}
}
Once version 1 is working correctly, add method to class and call it isEven(num) that gets an int number and returns true if the number is even, and false otherwise. Call this method inside your loop (which is inside the main method) and replace it with whatever you had for checking whether or not count is even or odd.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
