小编clc*_*cto的帖子

使用递归来反转整数而不使用字符串

我已经尝试了一段时间但是无法让它发挥作用.我试图有一个方法来反转整数而不使用字符串或数组.例如,123应以整数形式反转为321.

我的第一次尝试:

/** reverses digits of integer using recursion */
public int RevDigs(int input)
{
    int reverse = 0;
    if(input == 0)
    {
        return reverse;
    }
    int tempRev = RevDigs(input/10);
    if(tempRev >= 10)
        reverse = input%10 * (int)Math.pow(tempRev/10, 2) + tempRev;
    if(tempRev <10 && tempRev >0)
        reverse = input%10*10 + tempRev;
    if(tempRev == 0)
        reverse = input%10;   
    return reverse;
}//======================
Run Code Online (Sandbox Code Playgroud)

我也尝试过使用它,但似乎搞乱了中间数字:

/** reverses digits of integer using recursion */
public int RevDigs(int input)
{
    int reverse = 0;
    if(input == …
Run Code Online (Sandbox Code Playgroud)

java recursion integer

0
推荐指数
2
解决办法
7111
查看次数

学习C++,我不知道我在这里做错了什么

我正在学习C++,并且我被要求使用while函数编写代码.代码运行,但它给出不打印行Dear ....我在这做错了什么?

    cout << "Hello! Please write your recipient and the letter, then press enter:\n";
string name{ "" };
string current{ "" };
string letter{ "" };
cin >> name;
while (cin >> current){
    if (current != name){
        letter += " " + current;
    }
}
cout << "Dear " << name << "," << letter;
keep_window_open();
return 0;
Run Code Online (Sandbox Code Playgroud)

c++

0
推荐指数
1
解决办法
99
查看次数

为什么要修改内存地址?

我有这个代码序列:

printf("%p\n", gameGUI);
printf("label %p\n", gameGUI->labelRoundType);
gui_setRoundType(gameGUI->labelRoundType,
                 gameGUI->game->rounds[roundId]);
printf("label %p\n", gameGUI->labelRoundType);
printf("%p\n", gameGUI);
Run Code Online (Sandbox Code Playgroud)

函数gui_setRoundType的代码.

int gui_setRoundType(GtkWidget *roundTypeLabel, struct Round *round)
{
    if (round == NULL)
        return ROUND_NULL;
    if (roundTypeLabel == NULL)
        return POINTER_NULL;

    char type[1] = { '\0' };
    intToChar(round->roundType, type);
    gtk_label_set_text(GTK_LABEL(roundTypeLabel), type);

    return NO_ERROR;
}
Run Code Online (Sandbox Code Playgroud)

GameGUI结构的代码:

struct GameGUI {
    struct Game *game;
    struct Select *select;
    struct PlayerCards *playerCards;
    struct PlayersGUI *playersGUI;
    struct CardsFromTable *cardsFromTable;
    struct BidGUI *bidGUI;
    GtkWidget *windowTable;
    GtkWidget *fixedTable;
    GtkWidget *buttonShowScore;
    GtkWidget *imageTrump;
    GtkWidget *labelRoundType;
    GtkWidget *labelNoOfBids; …
Run Code Online (Sandbox Code Playgroud)

c gtk

0
推荐指数
1
解决办法
64
查看次数

声明为指针的函数

我已经看到以这种方式声明的某些函数:

char* encipher(const char *src, char *key, int is_encode);
Run Code Online (Sandbox Code Playgroud)

我不明白这一部分:

char* encipher
Run Code Online (Sandbox Code Playgroud)

数据类型后的星号是什么意思?

c

-3
推荐指数
2
解决办法
108
查看次数

从HashSet数组中按索引获取项目,并显示列表中每个项目的平均长度

嗨,我已经创建了使用HashSet数组的代码.我是Java编程的新手,我想知道如何完成这两项任务:

*从HashSet数组中按索引获取项目*显示列表中每个项目的平均长度

我的代码不长,所以我在这里粘贴整个代码.感谢你的帮助.

public class MainActivity extends Activity {

Button aButton; // Global Scope
Button sButton;
TextView text2;
EditText eText;
HashSet<String> list = new HashSet<String>();


@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.new_layout); 

    aButton = (Button) this.findViewById(R.id.button1);
    text2 = (TextView) this.findViewById(R.id.textView1);

    //Clickable Saved Input will display alert
    text2.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            Toast.makeText(getApplicationContext(), "Complete!", Toast.LENGTH_LONG).show();

        }
    });

    aButton.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {


            list.add("Books");
            list.add("Newspapers");
            list.add("Magazines");
            String listString = "";

            for (String s …
Run Code Online (Sandbox Code Playgroud)

java arrays

-3
推荐指数
1
解决办法
4万
查看次数

Java:检查一个数字是双位数还是单位数no if语句?

我有作业来检查数字是一个两位数还是一位数而不使用if语句.谢谢你的帮助!

public class SchoolTest {
    public static void main(String[] args) {
        Scanner reader = new Scanner(System.in);
        int x;
        System.out.println("Please enter a number");
        x = reader.nextInt();
        if ((x > 9 && x < 100) || (x < -9 && x > -100)) {
            System.out.println(true);
            main(args);
        } else {
            System.out.println(false);
            main(args);
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

java if-statement numbers digits

-4
推荐指数
1
解决办法
3万
查看次数

标签 统计

java ×3

c ×2

arrays ×1

c++ ×1

digits ×1

gtk ×1

if-statement ×1

integer ×1

numbers ×1

recursion ×1