🔧 Operators (if, else if, else, ternary operator, switch)
Nachrichtenbereich: 🔧 Programmierung
🔗 Quelle: dev.to
a) Quyidagi kodning natijasini ayting.
int temperature = 30;
if(temperature > 25)
{
Console.WriteLine("Hot");
}
else if(temperature > 15)
{
Console.WriteLine("Warm");
}
else
{
Console.WriteLine("Cold");
}
Javob. Hot
b) Switch operatoridan foydalanib, quyidagi if-else kodini switch operatoriga o'zgartiring.
int day = 3;
if(day == 1)
{
Console.WriteLine("Monday");
}
else if(day == 2)
{
Console.WriteLine("Tuesday");
}
else if(day == 3)
{
Console.WriteLine("Wednesday");
}
else
{
Console.WriteLine("Invalid day");
}
switchda
int day = 3;
switch(day)
{
case 1:
Console.WriteLine("Monday"); break;
case 2:
Console.WriteLine("Tuesday"); break;
case 3:
Console.WriteLine("Wednesday"); break;
default:
Console.WriteLine("Invalid day"); break;
}
c) Ternary operator yardamida quyidagi kodni qisqartiring.
int a = 10;
string result;
if(a > 5)
{
result = "Greater than 5";
}
else
{
result = "Less than or equal to 5";
}
🔧 Operators (if,else if,ternary operator,switch)
📈 60.68 Punkte
🔧 Programmierung
🔧 Don't nest ternary operators. Please!
📈 33.95 Punkte
🔧 Programmierung
🔧 Read This if You Hate Ternary Operators
📈 33.95 Punkte
🔧 Programmierung
🔧 Read This if You Hate Ternary Operators
📈 33.95 Punkte
🔧 Programmierung
🔧 What is The Ternary Operator In JavaScript ?
📈 33.17 Punkte
🔧 Programmierung
🔧 34.Operators (Bitwise Operators)
📈 24.24 Punkte
🔧 Programmierung
🔧 Operators (Logical Operators)
📈 24.24 Punkte
🔧 Programmierung
🔧 33.Operators (Logical Operators)
📈 24.24 Punkte
🔧 Programmierung
🔧 33.Operators (Logical Operators)
📈 24.24 Punkte
🔧 Programmierung