write a program in java to find out if the number is divisible by 2 or not???
Answers
Answered by
1
Heya!!! here is ur answer....
public class divisible
{
public static void main(int n)
{
int d;
while (n!=0)
{
d= n% 10;
n = n/10;
{
if (d% 2==0)
System.out.println("the number is divisible by 2");
else
System.out.println ("not divisible by 2")
}
}
}
}
public class divisible
{
public static void main(int n)
{
int d;
while (n!=0)
{
d= n% 10;
n = n/10;
{
if (d% 2==0)
System.out.println("the number is divisible by 2");
else
System.out.println ("not divisible by 2")
}
}
}
}
shinyyy:
wlcm
Answered by
1
Java program for the above question is as follows:
Explanation:
import java.util.Scanner;
public class Divison
{
public static void main(String[] args)
{
Scanner input = new Scanner(System.in);
System.out.println("Enter a number to find it is divisble by 2 or not");
int number = input.nextInt();
if(number%2==0)
System.out.println("The number is divisble by 2");
else
System.out.println("The number is not divisble by 2");
}
}
output :
- If the user input as 4, then the output is divisible.
- If the user input as 5, then the output is not divisible.
Code Explanation :
- The above code is in java, which takes the input from the user.
- Then check that input is a divisible by the 2 or not
Learn more :
- Java : https://brainly.in/question/13792074
Similar questions
Math,
8 months ago
Math,
1 year ago
Physics,
1 year ago
Social Sciences,
1 year ago
Science,
1 year ago