Monday, December 19, 2022

if else in java, python 3, c++ and javascript

 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

meta.ai impression

Meta.ai is released by meta yesterday, it is super fast you can generate image while typing! You can ask meta.ai to draw a cat with curvy fu...