PROGRAM 1: Write a program to input a number and check whether it is divisible by 2 and 3 both.
Answers
Answered by
1
Answer:
// Java program to print all the numbers
// divisible by 3 and 5 for a given number
class GFG{
// Result function with N
static void result(int N)
{
// iterate from 0 to N
for (int num = 0; num < N; num++)
{
// Short-circuit operator is used
if (num % 3 == 0 && num % 5 == 0)
System.out.print(num + " ");
}
}
// Driver code
public static void main(String []args)
{
// input goes here
int N = 100;
// Calling function
result(N);
}
}
Similar questions