25秋問5

てるおさん  
(No.1)
25年秋問5をJAVAでつくってみました。
ご指導いただければ幸いです。

class AP25aki5 {
static int[] array = new int[10];
static int b = 0;
public static void main(String[] args) {
push(1);
push(5);
pop();
push(7);
push(6);
push(4);
pop();
pop();
push(3);
for(int m = 0;m < 10;m++) {
if(array[m] != 0 ) {
System.out.print(array[m]);
System.out.print(" ");
}
}

}
static void push(int a) {
array[b] = a;
b = b + 1;
}
static void pop() {
b = b - 1;
array[b] = 0;
}
}
2015.08.18 18:52
てるおさん  
(No.2)
失礼しました。24年秋問5です。
for文を書き直しました。

class AP24aki5 {
static int[] array = new int[10];
static int b = 0;
public static void main(String[] args) {
push(1);
push(5);
pop();
push(7);
push(6);
push(4);
pop();
pop();
push(3);
for(int m = 0;m < b;m++) {
System.out.print(array[m]);
System.out.print(" ");
}

}
static void push(int a) {
array[b] = a;
b = b + 1;
}
static void pop() {
b = b - 1;
array[b] = 0;
}
}
2015.08.19 19:35

返信投稿用フォーム

スパム防止のためにスレッド作成日から30日経過したスレッドへの書込みはできません。

その他のスレッド


Pagetop