51Nod【3429】-条件输出5
- 作者: 执丶落
- 来源: 51数据库
- 2021-10-25
题目
编程实现输入两个整数a,b,当a≥b时,输出a的值,否则输出0。
你知道如何不使用 if,switch以及 3 目运算符,来解决这个问题么?
?收起
输入
输入两个正整数a,b
输出
输出一个数表示结果。
数据范围
对于100%的数据,1≤a,b≤1000。
输入样例
4 3
输出样例
4
C:
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int main() {
int a,b;
scanf("%d %d",&a,&b);
printf("%d",(a>b)*a);
return 0;
}
Java:
import java.util.*;
public class testOne {
public static void main(String[] args) {
Scanner input=new Scanner(System.in);
int a=input.nextInt();
int b=input.nextInt();
int f=Boolean.compare(a>b,false);
System.out.printf("%d",f*a);
input.close();
}
}
?
推荐阅读