Here is how you can write an if/else statement in each of the languages:
Java:
int x = 10; if (x > 0) { System.out.println("x is positive"); } else if (x < 0) { System.out.println("x is negative"); } else { System.out.println("x is zero"); }
Python 3:
x = 10 if x > 0: print('x is positive') elif x < 0: print('x is negative') else: print('x is zero')
C++:
int x = 10; if (x > 0) { std::cout << "x is positive" << std::endl; } else if (x < 0) { std::cout << "x is negative" << std::endl; } else { std::cout << "x is zero" << std::endl; }
JavaScript:
const x = 10; if (x > 0) { console.log('x is positive'); } else if (x < 0) { console.log('x is negative'); } else { console.log('x is zero'); }
I hope this helps! Let me know if you have any questions.
No comments:
Post a Comment