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

Why I stopped publishing blog posts as information provider

Now the AI can generate content. Does that mean the web publishing industry reaches the end? ChatGPT said: ChatGPT Not at all. While AI can ...