概要
vistaでandroid studio 1.1.0やってみた。
jniやってみた。
練習問題やってみた。
練習問題
jniでfizzbuzzを表示せよ。
写真
サンプルコード
#include <jni.h>
#include <stdio.h>
#include <string.h>
JNIEXPORT jstring JNICALL Java_com_ohisamallc_ohiapp154_ohiapp154_MainActivity_hello(JNIEnv * env, jobject thiz) {
char buf[456];
char n[8];
const char * s0 = "fizz ";
const char * s1 = "buzz ";
const char * s2 = "fizzbuzz ";
int i;
for (i = 1; i < 101; i++)
{
if (i % 15 == 0)
{
strcat(buf, s2);
}
else if (i % 5 == 0)
{
strcat(buf, s1);
}
else if (i % 3 == 0)
{
strcat(buf, s0);
}
else
{
sprintf(n, "%d ", i);
strcat(buf, n);
}
}
return (* env)->NewStringUTF(env, buf);
}
以上。