
Ternary,GCD,Prime number in three languages
Ternary A ternary operator is a short form of an if-else statement that takes three parts (three operands) — that’s why it’s called ternary. Syntax condition ? value_if_true : value_if_false ; Find Largest of 3 Numbers Java int a = 10 , b = 25 , c = 15 ; int max = ( a > b ) ? ( a > c ? a : c ) : ( b > c ? b : c ); System . out . println ( "Largest = " + max ); javascript let a = 10 , b = 25 , c = 15 ; let max = ( a > b ) ? ( a > c ? a : c ) : ( b > c ? b : c ); console . log ( " Largest = " , max ); python a , b , c = 10 , 25 , 15 max_val = a if ( a > b and a > c ) else ( b if b > c else c ) print ( " Largest = " , max_val ) Prime numbers in given range java public class Prime { public static void main ( String [] args ) { int first = 10 ; int last = 50 ; while ( first <= last ) { int div = 2 ; boolean flag = true ; while ( div <= first / 2 ) { if ( first % div == 0 ) { flag = false ; break ; } div += 1 ; } if ( flag && first > 1 ) { System . out . println ( first + " is prime number"
Continue reading on Dev.to Python
Opens in a new tab




