using UnityEngine;

using System.Collections;


public class ExWhile5: MonoBehaviour {


// Use this for initialization

void Start () {

string[] npc_name = new string[]{"npc1", "npc2""npc3", "boss", "npc4"} ;

int[] npc_hp = new int[]{-100, -150, -200, -1000, -250} ;

int i;

string text;

int max_hp = int.MinValue; //at least error no minvalue

//float max_mp = float.MinValue;

int min_hp = int.MaxValue;

string max_name = "";

string min_name="";

for(i=0; i < npc_name.Length; i++){

text = npc_name[i] + "," + " [" + npc_hp[i] + "]";

print (text);

if( max_hp < npc_hp[i]){

max_hp = npc_hp[i];

  max_name = npc_name[i];

}

if( min_hp > npc_hp[i]){

min_hp = npc_hp[i];

min_name = npc_name[i];

}

}

print("max= " + max_hp + ", npc_name= " + max_name);

print ("min= " + min_hp + ", min_name= " + min_name);


}

// Update is called once per frame

void Update () {

}

}




'Computer Language > 유니티' 카테고리의 다른 글

변태같은 코드 ㅋㅋㅋ for문  (0) 2014.04.04
pow 2의 제곱승 2014 출력하기  (0) 2014.04.04
while문& for문 별찍기 놀이  (0) 2014.04.04
while  (0) 2014.04.04
배열  (0) 2014.03.31

1. 이중 while

using UnityEngine;

using System.Collections;


public class ExWhile4 : MonoBehaviour {

void Start(){

int[] count = new int[]{7, 2, 3, 4, 5, 4, 3, 4, 1, 0} ;

int row = -1;

int col = 0;

int sum = 0;

string text = " ";

while(true){

row += 1;

print (count[row]);

if(count[row] == 0){

break;

}

col = 0;

text = " ";

while(col<count[row]){

col +=1;

text = text + "*";

}

print (text);

}

}

}



2. 2중 for

using UnityEngine;

using System.Collections;


public class ExWhile4 : MonoBehaviour {

void Start(){

int[] count = new int[]{7, 2, 3, 4, 5, 4, 3, 4, 1, 0} ;

int row = -1;

int col = 0;

int sum = 0;

string text = " ";

for(row = 0; count[row]>0; row++){

//print(count[row]);

text = " ";

for(col = 0; col < count[row]; col++){

text = text + "*";

}

print (text);

}

}

}

3. while문 for문

using UnityEngine;

using System.Collections;


public class ExWhile4 : MonoBehaviour {

void Start(){

int[] count = new int[]{7, 2, 3, 4, 5, 4, 3, 4, 1, 0} ;

int row = -1;

int col = 0;

int sum = 0;

string text = " ";

while(true)

{

row++;

if(count[row]==0){

break;

}

col = 0;

text = " ";

//for

for(col =0; col < count[row]; col++){

text = text + "*";

}

print(text);

// }

}

}

}



'Computer Language > 유니티' 카테고리의 다른 글

pow 2의 제곱승 2014 출력하기  (0) 2014.04.04
npc 최대값 최소값 이름 출력  (0) 2014.04.04
while  (0) 2014.04.04
배열  (0) 2014.03.31
C# String Format  (0) 2014.03.31

using UnityEngine;

using System.Collections;


public class ExWhile : MonoBehaviour {


// Use this for initialization

void Start () {

string[] names = new string[]{

"Hello", "Inha", "Pass","Pass1", "Quit", "Morning" 

} ;

int i = -1;

while(true){

i++;

if(names[i] == "Pass"){

continue;

}

if(names[i] == "Pass1"){

continue;

}

print (names[i]);

if(names[i] == "Quit")

break;

}

}

// Update is called once per frame

void Update () {

}


}

'Computer Language > 유니티' 카테고리의 다른 글

npc 최대값 최소값 이름 출력  (0) 2014.04.04
while문& for문 별찍기 놀이  (0) 2014.04.04
배열  (0) 2014.03.31
C# String Format  (0) 2014.03.31
형변환  (0) 2014.03.31

+ Recent posts