实现等级到分数的换算
case: level to grade
read -n 1 -p "Type a character > "
echo
case $REPLY in
A) echo "'$REPLY' is 90-100" ;;
B) echo "'$REPLY' is 80-90" ;;
C) echo "'$REPLY' is 70-80" ;;
D) echo "'$REPLY' is 60-70" ;;
E) echo "'$REPLY' is <60" ;;
*) echo "'$REPLY' is error" ;;
esac
实现分数到等级的换算
case: grade to level
read -n 2 -p "Type a grade > "
echo
case $REPLY in
9[0-9]) echo "'$REPLY' is A" ;;
8[0-9]) echo "'$REPLY' is B" ;;
7[0-9]) echo "'$REPLY' is C" ;;
6[0-9]) echo "'$REPLY' is D" ;;
*) echo "'$REPLY' is E" ;;
esac
三种循环实现输出一个数的反转数 321-123
test 'for'
read a
for ((b=0;a>0;)); do
b=$((b*10+a%10));
a=$((a/10));
done
echo $b;
test 'until'
read a
b=0;
until (($a==0)); do
b=$((b*10+a%10));
a=$((a/10));
done
echo $b;
test 'while'
read a
b=0;
while (($a>0)); do
b=$((b*10+a%10));
a=$((a/10));
done
echo $b;