MST

星途 面试题库

面试题:Rust布尔类型在条件判断中的基础应用

请编写一段Rust代码,使用布尔类型变量在`if - else`语句中判断两个整数变量`a`和`b`的大小关系。如果`a`大于`b`,打印`a is greater than b`;如果`a`小于`b`,打印`a is less than b`;如果`a`等于`b`,打印`a is equal to b`。
28.5万 热度难度
编程语言Rust

知识考点

AI 面试

面试题答案

一键面试
fn main() {
    let a = 5;
    let b = 3;
    let is_a_greater_than_b = a > b;
    let is_a_less_than_b = a < b;
    let is_a_equal_to_b = a == b;

    if is_a_greater_than_b {
        println!("a is greater than b");
    } else if is_a_less_than_b {
        println!("a is less than b");
    } else if is_a_equal_to_b {
        println!("a is equal to b");
    }
}