Hi ALL,
Here I wrote a program for Finding Common Divisor using Conditional Operators in Java.
/**
*
* @author Balamurgan
M
*/
import java.util.Scanner;
public class OperatorExample {
public static void
main(String arg[]){
System.out.println("Please enter number :");
Scanner in=new
Scanner(System.in);
int
num=in.nextInt();
if(((num %2
)==0)&&((num%3)==0))
System.out.println(" Given number divisional by 2 and 3
"+num);
else if(((num
%2 )==0)||((num%3)==0))
System.out.println(" Given number divisional by 2 or 3 "+num);
else if
(!((num %2 )==0)||((num%3)==0))
System.out.println(" Given number Not divisional by 2 3 "+num);
}
}
No comments:
Post a Comment