奇数偶数判定
AppleScript サンプルコード
行番号 | ソース |
---|---|
001 | #!/usr/bin/env osascript |
002 | ----+----1----+----2----+-----3----+----4----+----5----+----6----+----7 |
003 | # com.cocolog-nifty.quicktimer.icefloe |
004 | # |
005 | # |
006 | ----+----1----+----2----+-----3----+----4----+----5----+----6----+----7 |
007 | use AppleScript version "2.8" |
008 | use scripting additions |
009 | |
010 | |
011 | #奇数偶数判定 |
012 | #値が整数の場合 |
013 | set numCnkNo to 1234567 as integer |
014 | |
015 | set numChkPageOddEven to (numCnkNo mod 2) as integer |
016 | if numChkPageOddEven = 1 then |
017 | log "奇数" |
018 | else if numChkPageOddEven = 0 then |
019 | log "偶数" |
020 | end if |
021 | |
022 | |
023 | set numCnkNo to 12345678 as integer |
024 | |
025 | set numChkPageOddEven to (numCnkNo mod 2) as integer |
026 | if numChkPageOddEven = 1 then |
027 | log "奇数" |
028 | else if numChkPageOddEven = 0 then |
029 | log "偶数" |
030 | end if |
031 | |
032 | |
033 | #値が小数点以下の値を持っている場合 |
034 | set numCnkNo to 11.7 as number |
035 | |
036 | set numChkPageOddEven to (round of (numCnkNo mod 2) rounding down) as integer |
037 | if numChkPageOddEven = 1 then |
038 | log "奇数" |
039 | else if numChkPageOddEven = 0 then |
040 | log "偶数" |
041 | end if |
042 | |
043 | |
044 | set numCnkNo to 12.7 as number |
045 | |
046 | set numChkPageOddEven to (round of (numCnkNo mod 2) rounding down) as integer |
047 | if numChkPageOddEven = 1 then |
048 | log "奇数" |
049 | else if numChkPageOddEven = 0 then |
050 | log "偶数" |
051 | end if |
052 | |
AppleScriptで生成しました |
| 固定リンク