小编Piz*_*man的帖子

Shell脚本 - 如果目录不存在则创建目录

我想输入目录的名称并检查它是否存在.如果它不存在我想创建但我得到错误mkdir: cannot create directory'./' File exists

我的代码说文件存在,即使它不存在.我究竟做错了什么?

echo "Enter directory name"
read dirname

if [[ ! -d "$dirname" ]]
then
    if [ -L $dirname]
then
    echo "File doesn't exist. Creating now"
    mkdir ./$dirname
    echo "File created"
    else
        echo "File exists"
    fi
fi
Run Code Online (Sandbox Code Playgroud)

directory shell mkdir

7
推荐指数
4
解决办法
6万
查看次数

Javascript检查字符是否为元音

我在这里看了很多与我有关的问题,但他们都使用不同的方法来处理我必须使用的方法.我知道这是一个非常漫长的方式来找出有更简单的方法,但我只是按照说明.

为什么以下代码不起作用?该函数检查它是否是元音.然后检查输入以查看它的长度是否为1.如果为1,则调用该函数.如果它大于1,则在长度为1之前请求另一个输入.

我现在看到JS中不存在布尔值.我想这个问题现在无效!

function isVowel(x){

    boolean result;

        if(x == "A" || x == "E" || x == "I" || x == "O" || x == "U" ) {
            result = true;
        }
        else{
            result = false;
        }
    return result;
    }

    var input;


    input = prompt("Enter a character ");
    input = input.toUpperCase();
    if(input.length == 1){
        isVowel(input);
        }
    }
    else{
        while(input.length != 1){
            prompt("Enter a character ");
            if(input.length == 1){
                isVowel(input);
            }
        }
    }

    alert(isVowel(input));
Run Code Online (Sandbox Code Playgroud)

javascript character

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

在循环中查找最低奇数

我知道这段代码错了.我是初学者所以请耐心等待.

我需要找到最低的奇数,但无论输入什么数字,它都会保持为零.我需要初始化'最低',但我如何/在哪里初始化它?

最低= 0导致问题,但我不确定在哪里初始化最低

class Odd

{
    public static void main(String[] args)
    {
        int number; //the number entered by the user
        int input; //the amount of numbers to be entered by the user
        int index;
        int lowest = 0; //lowest odd number

        System.out.println("How many numbers? ");
        input = EasyIn.getInt();

    for (index = 1; index <= input ; index ++) 
        {
            System.out.println("Enter number " + index + ":" );
            number = EasyIn.getInt();

            if ((number % 2 == 1) && (number < …
Run Code Online (Sandbox Code Playgroud)

java

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

在循环中找到最高,最低和平均值

我知道这可能是我做错了.我希望它在循环结束时打印最小数字等,但它总是打印为最低的零.如何让它不将退出机制归零为最低数字.

有什么建议吗?

class HighLowAve
{
    public static void main (String[]args)
    {
        int num =0;
        int sum;
        int highest;
        int lowest;
        int index;
        Double average;

        highest = num;
        lowest = num;
        sum = 0;
        index = 0;

        do
        {
            System.out.println("Enter a number. Press zero to quit ");
            num = EasyIn.getInt();

            if (num > highest)
            {
                highest = num;
            }
            else if (num < lowest) 
            {
                lowest = num;
            }

            sum = sum + num;
            index++;
        }while (num !=0);

        average = (double) …
Run Code Online (Sandbox Code Playgroud)

java while-loop

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

摄氏/华氏转换器

函数代码中似乎存在问题,因为函数无法运行之后的所有内容。

我通过conversion在2个函数中为变量赋予值并返回该值来对其进行测试。当时行得通。

function celsius(input) { /*convert to Celsius*/

    var conversion = 5;
    /*conversion = (5.0 / 9.0) * (input – 32);*/

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

这是实际的代码。当我运行它时,什么也没有发生。我必须在函数中使用parseFloat吗?

function celsius(input) { /*convert to Celsius*/

    var conversion;
    conversion = (5.0 / 9.0) * (input – 32);

    return conversion;
}

function fahrenheit(input) { /*convert to Fahrenheit*/

    var conversion;
    conversion = (9.0 / 5.0) * (input + 32);

    return conversion;
}

var temp; /*temperature that will be converted*/
temp = parseFloat(prompt("Enter a temperature to …
Run Code Online (Sandbox Code Playgroud)

javascript converter temperature

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