我需要一个函数,将5作为参数传入并返回7,反之亦然。

huangapple go评论64阅读模式
英文:

I need a function for putting 5 as argument and return 7 and vice versa

问题

创建一个具有一个int类型参数/参数的方法/函数。如果用户传递5个值,则它将返回7,如果用户输入7,则返回5。但重要的是,我不允许使用任何条件操作,如==,<,>,<=,>=,if else,三元运算符,switch语句,while循环和任何内置方法。

英文:

Make a method/function with one parameter/argument of int type. if user pass 5 value then it will return 7 and if user put 7 it will return 5 . but important thing is that I was not allowed to use any conditional operation like == , <, >, <=, >=, if else, ternary operator ,switch statement , while, for loop and any built in method.

答案1

得分: 6

public int fiveOrSeven(int input){
    return 35 / input;
}
英文:
public int fiveOrSeven(int input){
    return 35 / input;
}

huangapple
  • 本文由 发表于 2020年8月7日 02:13:56
  • 转载请务必保留本文链接:https://go.coder-hub.com/63289464.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定