陣列的陣列是指數組元素也是陣列變數。
所胃陣列的陣列,是指在乙個陣列中存放幾個子陣列,也就是說,陣列的元素也是乙個陣列。陣列的陣列與多維陣列的區別是,多維陣列等價於乙個矩陣,而陣列的陣列的元素個數並不規則。
宣告陣列的陣列採用如下形式:
dim yeardays ()() as integer
可以在宣告時為該陣列賦初值:
dim yeardays()() as integer = new integer(11)() {}
上面這行**宣告了乙個名為yeardays的陣列,這個陣列有12個元素,每乙個元素都是乙個integer整數型別的陣列。
module module1
sub main()
test2()
end sub
private sub test1()
dim jaggednumbers = ), (), (), ()}
for indexa = 0 to jaggednumbers.length - 1
for indexb = 0 to jaggednumbers(indexa).length - 1
console.write(jaggednumbers(indexa)(indexb) & " ")
next
console.writeline()
next
console.readline()
end sub
private sub test2()
dim yeardays()() as integer = new integer(11)() {}
dim imonth, jdays, baseday, skipdays as integer
dim ndays() as integer =
'console.writeline(yeardays.getlength(0))
'console.readline()
for imonth = 0 to yeardays.getlength(0) - 1
yeardays(imonth) = new integer(ndays(imonth) - 1) {}
next
'for imonth = 0 to yeardays.length - 1
'console.write(yeardays(imonth).length & ",")
'next
'console.readline()
baseday = 3
skipdays = 0
for imonth = 0 to 11
for jdays = 0 to ndays(imonth) - 1
yeardays(imonth)(jdays) = (skipdays + baseday - 1) mod 7 + 1
skipdays += 1
next
next
'for imonth = 0 to yeardays.length - 1
'for jdays = 0 to yeardays(imonth).length - 1
'console.write(yeardays(imonth)(jdays) & ",")
'next
'console.readline()
'next
dim querymonth as integer = 0, queryday as integer
while querymonth < 1 or querymonth > 12
console.writeline("請輸入要查詢的月份")
querymonth = convert.toint32(console.readline())
end while
while queryday < 1 or queryday > ndays(querymonth - 1)
console.writeline("請輸入要查詢月的哪一天", querymonth)
queryday = cint(console.readline)
end while
console.writeline("你查詢的是月日", querymonth, queryday)
console.writeline("這一天是星期", yeardays(querymonth - 1)(queryday - 1))
console.readline()
end sub
end module
陣列的擴充套件 陣列例項的copyWithin
陣列例項的copywithin 方法,在當前陣列的內部,將指定位置的成員複製到其他位置 會覆蓋原有成員 然後返回當前陣列。也就是說,使用這個方法,會修改當前陣列。語法 array.prototype.copywithin target,start 0,end this.length 它接受三個引數,...
陣列的擴充套件 陣列例項的fill
fill方法使用給定值填充乙個陣列 a b c fill 7 7,7,7 new array 3 fill 7 7,7,7 上面 表明,fill方法用於空陣列的初始化非常方便。陣列中已有的元素,會被全部抹去。fill方法還可以接受第二個和第三個引數,用於指定填充的起始位置和結束位置。a b c fi...
Python練習例項011
問題 古典問題 有一對兔子,從出生後第3個月起每個月都生一對兔子,小兔子長到第三個月後每個月又生一對兔子,假如兔子都不死,問每個月的兔子總數為多少?usr bin env python3 coding utf 8 author ma yi blog date 2020 06 18 name demo...