0
0

More than 1 year has passed since last update.

vistaでandroid studio その20

Posted at

概要

vistaでandroid studio 1.1.0やってみた。
jniやってみた。
練習問題やってみた。

練習問題

jniでfizzbuzzを表示せよ。

写真

device-2022-09-13-065334.png

サンプルコード


#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);
}

以上。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0