cscの作法 その4 fizzbuzz
1776 ワード
概要
cscの作法、調べてみた。
fizzbuzzやってみた。
textbox使ってみた。
写真
サンプルコード
using System;
using System.Windows.Forms;
using System.Drawing;
class form1: Form {
TextBox bo1;
form1() {
Text = "fizzbuzz";
ClientSize = new Size(300, 300);
bo1 = new TextBox();
bo1.Location = new Point(50, 80);
bo1.Width = 200;
bo1.Height = 200;
bo1.Multiline = true;
Controls.AddRange(new Control[] {
bo1
});
Button btn1 = new Button();
btn1.Location = new Point(50, 50);
btn1.Text = "test";
btn1.Click += btn1_Click;
Controls.AddRange(new Control[] {
btn1
});
}
void btn1_Click(object sender, System.EventArgs e) {
int i;
string res = "";
for (i = 1; i < 100; i++)
{
if (i % 15 == 0)
{
res += "fizzbuzz ";
}
else if (i % 5 == 0)
{
res += "buzz ";
}
else if (i % 3 == 0)
{
res += "fizz ";
}
else
{
res += i.ToString() + " ";
}
}
bo1.Text = res;
}
[STAThread]
public static void Main() {
Application.Run(new form1());
}
}
using System;
using System.Windows.Forms;
using System.Drawing;
class form1: Form {
TextBox bo1;
form1() {
Text = "fizzbuzz";
ClientSize = new Size(300, 300);
bo1 = new TextBox();
bo1.Location = new Point(50, 80);
bo1.Width = 200;
bo1.Height = 200;
bo1.Multiline = true;
Controls.AddRange(new Control[] {
bo1
});
Button btn1 = new Button();
btn1.Location = new Point(50, 50);
btn1.Text = "test";
btn1.Click += btn1_Click;
Controls.AddRange(new Control[] {
btn1
});
}
void btn1_Click(object sender, System.EventArgs e) {
int i;
string res = "";
for (i = 1; i < 100; i++)
{
if (i % 15 == 0)
{
res += "fizzbuzz ";
}
else if (i % 5 == 0)
{
res += "buzz ";
}
else if (i % 3 == 0)
{
res += "fizz ";
}
else
{
res += i.ToString() + " ";
}
}
bo1.Text = res;
}
[STAThread]
public static void Main() {
Application.Run(new form1());
}
}
以上。
Author And Source
この問題について(cscの作法 その4 fizzbuzz), 我々は、より多くの情報をここで見つけました https://qiita.com/ohisama@github/items/e2874aaad7431062ec3d著者帰属:元の著者の情報は、元のURLに含まれています。著作権は原作者に属する。
Content is automatically searched and collected through network algorithms . If there is a violation . Please contact us . We will adjust (correct author information ,or delete content ) as soon as possible .