突然このブログ見たあなた・・・・
ごめんなさいm(_ _ )m
このブログは私的備忘録ちっくな使い方をしているので、
コンテンツとしては一部の変態さん以外全く面白みが無いとおもわれ
ます。
したがって一部の変態さん以外はどうぞ広大な
Webの世界へお戻り頂きますこと心より望みます。
PrintaRectangle
/**
* たてH cm よこ W cm の長方形を描くプログラムを作成して下さい。
* 1 cm × 1cm の長方形を '#'で表します。
* Input 入力は複数のデータセットから構成されています。
* 各データセットの形式は以下のとおりです:
* H W H,Wがともに0の時入力は終了。
* 各データセットの後に、1つの空行を入れて下さい。
* 条件 H, W ? 300
* @version 1.0
* @author otaenta
*/
import java.util.Scanner;
class PrintaRectangle{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);//スキャナー作る
StringBuilder all = new StringBuilder();//合計用?変数
StringBuilder out = new StringBuilder();//表示用変数
while(true){//----------------------------------+
int h = sc.nextInt();//縦取り込み
int w = sc.nextInt();//横取り込み
if((h + w) <= 0){break;}//入力が 0 0 なら 繰り返し終了
for(int j = 0; j < h; j++){//縦の計算----------------++
for(int i = 0; i < w; i++){//横の計算//----------+++
out = out.append("#");//out に横の数ぶん#格納
}//-----------------------------------------------+++
out = out.append("\n");//outに改行コード格納
}//--------------------------------------------------++
all = all.append(out + "\n");//格納した文字列と改行文字をallに格納
out.delete(0, out.length());//outを初期化
}//----------------------------------------------+
//0 0が入力されループ抜けたのでallに格納された全てを表示
System.out.print(all);
}
}
/**
* StringBuilderクラス。
* 文字列を追加整形するメソッド
* 引数.append(String str);
* String 引数の文字が追加される。
* 引数の長さの分だけ文字列の長さが増える
* ※str = null n u l l の4文字が返される。
*/
PrintaFrame
PrintaFrame
**
* たてH cm よこ W cm の枠を描くプログラムを作成して下さい。
* 1 cm × 1cm の長方形を '#'で表します。
* Input 入力は複数のデータセットから構成されています。
* 各データセットの形式は以下のとおりです:
* H W H,Wがともに0の時入力は終了。
* 各データセットの後に、1つの空行を入れて下さい。
* 条件 3<=H,W<=100
* @version 1.0
* @author otaenta
*/
import java.util.Scanner;
class PrintaFrame{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
StringBuilder all = new StringBuilder();
StringBuilder out = new StringBuilder();
while(true){
int h = sc.nextInt();
int w = sc.nextInt();
if((h + w) <= 0){break;}
//top
for(int t = 0; t < w; t++){
out = out.append("#");
}
out = out.append("\n");
//center
for(int j = 0; j < (h-2); j++){
out = out.append("#");
for(int i = 0; i < (w-2); i++){
out = out.append(".");
}
out = out.append("#");
out = out.append("\n");
}
//bottom
for(int b = 0; b < w; b++){
out = out.append("#");
}
out = out.append("\n");
//inputAll
all = all.append(out + "\n");
out.delete(0, out.length());
}
//output
System.out.print(all);
}
}
