这是我的脚本:
echo "Name"
read name
if [ "$name" == "abcd" ]; then
echo "Password"
read password
if [ "$password == "pwd" ]; then
echo "Hello"
else
echo "Wrong password"
fi
else
echo "wrong username"
fi
Run Code Online (Sandbox Code Playgroud)
这是我运行时得到的输出:
sh hello.sh Name abcd hello.sh: line 14: unexpected EOF while looking for matching `"' hello.sh: line 16: syntax error: unexpected end of file
这里有什么想法吗?这可能是一个非常愚蠢的,但我浪费了将近一个小时.
我无法弄清楚为什么每次循环都没有正确加起来.当输入-9999时,while循环也没有输出和,这也是一个问题.
import java.util.*;
public class list
{
public static void main(String args [])
{
Scanner sc = new Scanner(System.in);
int Number, Sum = 0;
System.out.println("Enter the list of whole numbers, terminate by -9999> ");
Number = sc.nextInt();
Sum += Number;
while (Number != -9999)
{
if (Number > 1 && Number < 100)
{
Sum += Number;
Number = sc.nextInt();
}
else
System.out.println("Please enter a number between 1 and 100");
Number = sc.nextInt();
}
System.out.println("Sum is " + Sum);
} …Run Code Online (Sandbox Code Playgroud) 我有一段简单的代码,在大多数语言中都非常简单。我真的很想知道如何做到这一点。我如何将其转换为Elixir,而不会收到可怕的变量不安全警告?
dc = 1
sd = 5
sdi = 6
calc = 1
bc = 1
dd = 10
if (dc == 1)
csd = sd
bd = sd
p = sdi
if (calc == 1 && bc != 1) do
count = 1
else
count = 20
end
else
csd = dd
bd = dd
p = dd
count = 1
end
Run Code Online (Sandbox Code Playgroud) 我写了一个小程序,只需要通过查看电子邮件地址并将字母返回给字符来获取电子邮件发件人的姓名@.
我用两种方式编写了while循环,一种方式是循环,第二种方式是使用嵌套的if语句.两者是一样好还是一种优于另一种的首选方法?
循环启动时:
public void FindUserName() {
Scanner keyboard = new Scanner(System.in);
char symbol = ' ';
System.out.println("Please enter email!");
symbol = keyboard.findWithinHorizon(".", 0).charAt(0);
while (symbol != '@') {
System.out.print(symbol);
symbol = keyboard.findWithinHorizon(".", 0).charAt(0);
}
System.out.println();
}
Run Code Online (Sandbox Code Playgroud)
使用嵌套的if语句来破坏if symbol == '@'
public void FindUserName() {
Scanner keyboard = new Scanner(System.in);
char symbol = ' ';
System.out.println("Please enter email!");
while (symbol != '@') {
symbol = keyboard.findWithinHorizon(".", 0).charAt(0);
if (symbol == '@') {
break;
}
System.out.print(symbol);
}
System.out.println();
}
Run Code Online (Sandbox Code Playgroud) 请允许任何人指出我在下面给出的代码中做了什么错误,我得到编译错误,对于每个EndIF,必须提前对应的IF THank:
Public Function customavg(rng As Range, nr_weeks As Integer)
Dim total As Integer, count_rng_row As Integer, count_wk As Integer, counter_rng As Integer
total = 0
count_rng_row = rng.Rows.count
count_wk = 0
counter_rng = count_rng_row
For counter_rng = count_rng_row To 1
If count_wk < nr_weeks Then
If rng.Cells.Offset(0, -1) = "b" Then total = total + rng.Cells.Value
counter_rng = counter_rng - 1
count_wk = count_wk + 1
End If
'Else
' counter_rng = counter_rng - 0
' count_wk = count_wk …Run Code Online (Sandbox Code Playgroud) 我知道这是可能的:
a, b = 5, 10
print 'a' if a > b else 'b' # outputs b
Run Code Online (Sandbox Code Playgroud)
但是,如果我还有另一个变量“ c”怎么办?如何使用与这两个变量相同的逻辑类型使它们在同一行中打印?就像是?
a, b, c = 5, 10, 20
print 'a' if a > b elif 'b' if b > c else 'c' # is it possible?
Run Code Online (Sandbox Code Playgroud)
只需提及:我知道这是一个不好的做法,我只是想知道。
我试图在pl/sql块中编写嵌套的IF.我该如何正确安排.
IF r1.CABLE_TYPE = "A" THEN
var_root = FC_CPSCBPR1.C_111_SCPSCBP
Run Code Online (Sandbox Code Playgroud)
逻辑我现在必须包括在内
If var_root is "TRUE" /*If the value is populated*/
THEN
IF ...
THEN
Elsif var_root is "FALSE" /*If the value is not found*/
THEN
Run Code Online (Sandbox Code Playgroud) if (x>0 && x<6)
{
break;
}
else if(x>6)
{
break;
}
Run Code Online (Sandbox Code Playgroud)
相对
if (x>0)
{
if (x<6)
{
break;
}
}
else
{
if (x>6)
{
break;
}
}
Run Code Online (Sandbox Code Playgroud)
代码 1 不起作用,但代码 2 起作用。为什么?我是编程方面的超级菜鸟,所以请提供任何帮助。编程语言是C。
nested-if ×8
if-statement ×2
java ×2
while-loop ×2
c ×1
elixir ×1
logical-and ×1
loops ×1
plsql ×1
printing ×1
python ×1
shell ×1
unix ×1
vba ×1