Write a java program that reads from the user two integers n1 & n2, in order to display the
numbers between n1 and n2 (both included) that are multiple of 3, and display their count.
Answers
Answered by
0
Answer:
import java.util.*;
public class Main
{
public static void main(String[] args) {
ArrayList<Integer> list = new ArrayList<Integer>();
int threes = 0;
System.out.print("Enter a number:");
Scanner sc = new Scanner(System.in);
int n1 = sc.nextInt();
System.out.print("Enter another number:");
int n2 = sc.nextInt();
System.out.println("The numbers divisible by 3 between " + n1 + " and " + n2 + " are-");
for(int i = n1; i < n2; i++){
if(i%3 == 0){
list.add(i);
threes++;
}
}
for (int i : list){
System.out.println(i);
}
System.out.println("The count of numbers divisible by 3 is: " + threes);
}
}
Explanation:
Similar questions