[JAVA] How to write a ternary operator

Overview

--The ternary operator is written in different languages.

Python

score = 100
result = ""
if score >= 60:
    result = "Pass"
else:
    result = "failure"
print(result)

--Ternary operator

score = 100
result = "Pass" if score >= 60 else "不Pass"
print(result)

Java

Integer score = 100;
String result = "";
if(score>=60){
    result = "Pass";
}else{
    result = "failure";
}
System.out.println(result);

--Ternary operator

Integer score = 100;
String result = (score >= 60)?"Pass":"不Pass";
System.out.println(result);

C

int score = 100;
char *result;
if(score >= 60){
    result = "Pass";
}else{
    result = "failure";
}
printf("%s",result);

--Ternary operator

int score = 100;
char *result = (score >= 60) ? "Pass":"不Pass";
printf("%s",result);

C#

int score = 100;
string result = "";
if(score>=60){
    result = "Pass";
}else{
    result = "failure";
}
System.Console.WriteLine(result);

--Ternary operator

int score = 100;
string result = (score >= 60)?"Pass":"不Pass";
System.Console.WriteLine(result);

Recommended Posts

How to write a ternary operator
[Basic] How to write a Dockerfile Self-learning ②
How do you write the ternary operator (? :)
[Introduction to Java] How to write a Java program
[SpringBoot] How to write a controller test
How to write Rails
How to write dockerfile
How to write docker-compose
How to write Mockito
How to write migrationfile
How to write good code
Bit Tetris (how to write)
How to write java comments
How to leave a comment
[Refactoring] How to write routing
Great poor (how to write)
[Note] How to write Dockerfile/docker-compose.yml
How to write Junit 5 organized
How to write Rails validation
How to write Rails seed
To write a user-oriented program (1)
[Ruby] How to write blocks
How to write Rails routing
How to insert a video
How to create a method
How to write a unit test for Spring Boot 2
java: How to write a generic type list [Note]
How to write a date comparison search in Rails
How to write a core mod in Minecraft Forge 1.15.2
How to add columns to a table
Studying Java # 6 (How to write blocks)
[Rails] How to write in Japanese
How to write a migration from Rails datetime type to date type
How to make a Java container
How to sign a Minecraft MOD
How to make a JDBC driver
Baseball ball count (how to write)
[Java] How to create a folder
Rails on Tiles (how to write)
[Rails] How to write exception handling?
[Swift] How to send a notification
How to write Java variable declaration
How to make a splash screen
How to make a Jenkins plugin
How to make a Maven project
Y-shaped road tour (how to write)
How to write easy-to-understand code [Summary 3]
[RSpec] How to write test code
How to make a Java array
[Reading impression] "How to learn Rails, how to write a book, and how to teach"
[Xcode] How to add a README.md file
How to sort a List using Comparator
How to make a Java calendar Summary
A memorandum on how to use Eclipse
How to redo a deployment on Heroku
I want to write a nice build.gradle
How to insert a video in Rails
Summary of how to write annotation arguments
How to add a new hash / array
I want to write a unit test!
How to create a Maven repository for 2020