小编Her*_*uez的帖子

使用循环语句划分两个数字

嗨,我正在做一个java活动,它将分割两个给定的数字,而不使用"/"运算符.我想使用循环语句.

System.out.print("Enter Divident: ");
int ans1 = Integer.parseInt(in.readLine());
System.out.print("Enter Divisor: ");
int ans2 = Integer.parseInt(in.readLine());
Run Code Online (Sandbox Code Playgroud)

输出是:

  Enter Dividend: 25
  Enter Divisor 5
  5
Run Code Online (Sandbox Code Playgroud)

如何在不使用"ans1/ans2"的情况下解决这个问题

java division

3
推荐指数
1
解决办法
6812
查看次数

如何确保用户输入值?

我试图让这段代码验证用户输入的值.如果我使用gets(),但是当我将其更改为fgets()时它会停止工作.我希望它继续循环,直到用户输入至少1个字符但少于25个字符串的字符串.如果在我的代码中不明显,我是编程新手.谢谢!

int main(void)
{
    char input[25], inputNew[25];
    int i;
    int x;
    int y;
    do
    {
        printf("Please enter a string less then 25 characters!\n");
        fgets(input, sizeof(input), stdin);  
        y = strlen(input);  
    }
    while(y>25 || y<=0);

    for (i = 0; i <= strlen(input); i++)
    {
        inputNew[i] = toupper(input[i]);
        for (x = 1; x <= strlen(input); x+=2)
        {
        inputNew[x] = tolower(input[x]);
        }
    }
    printf("The new value is: %s.\n", inputNew);
return 0;
}
Run Code Online (Sandbox Code Playgroud)

c

2
推荐指数
1
解决办法
169
查看次数

标签 统计

c ×1

division ×1

java ×1