예제1)
class ArrayTest {
public static void main(String[] args) {
//int[] m; // 배열선언
//m=new int[3]; // 배열생성
//m[0]=25;
//m[1]=43;
//m[2]=78;
int[] m={25,43,78};
//System.out.println("m[0]="+m[0]);
//System.out.println("m[1]="+m[1]);
//System.out.println("m[2]="+m[2]);
for(int i=0; i<m.length; i++) {
System.out.println("m["+i+"]=" +m[i]);
}
System.out.println("--------------------");
for(int num : m) {
System.out.println(num);
}
}
}
-----------------------------------------------
예제2)
class DoWhileTest {
public static void main(String[] args) {
char a = 'A';
do{
System.out.print(a + " "); // A B.....Y
a++; // B C.....Z
}while(a<='Z');
}
}
----------------------------------------------
예제3)
class MultiFor {
public static void main(String[] args) {
int dan, i;
/*
for(dan=2; dan<=9; dan++) {
for(i=1; i<=9; i++) {
System.out.println( dan + "*" + i + "=" + (dan*i) );
}
System.out.println();
}
}
*/
for(i=2; i<=9; i++) {
for(dan=1; dan<=9; dan++) {
System.out.print( dan + "*" + i + "=" + (dan*i) +"\t") ;
}
System.out.println();
}
}
}
--------------------------------------------------------
예제4)
class WhileTest{
public static void main(String[] args) {
int a= 0;
while (a<10){
//a++;
//System.out.println(a);
System.out.println(++a );
}//while
}
}
--------------------------------------------------
예제5)
class WhileTest2 {
public static void main(String[] args) {
int a;
int cnt=0;
int sum= 0;
while(true) {
cnt++;
if(cnt>10) break;// while을 벗어나라
a=(int) (Math.random()*100);
System.out.println(a);
sum+=a;
}
System.out.println("탈출...");
System.out.println("합="+sum);
}
}
--------------------------------------------------
=============== Run ===================
예제1) m[0]=25
m[1]=43
m[2]=78
---------------------
25
43
78
++++++++++++++++++++++++++++++++++++++++
예제2) A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
++++++++++++++++++++++++++++++++++++++++
예제3) : 구구단이 옆으로 탭 ("\t") 위치 만큼 띄어서 출력됨!
1*2=2 2*2=4 3*2=6 4*2=8 5*2=10 6*2=12 7*2=14 8*2=16 9*2=18
1*3=3 2*3=6 3*3=9 4*3=12 5*3=15 6*3=18 7*3=21 8*3=24 9*3=27
1*4=4 2*4=8 3*4=12 4*4=16 5*4=20 6*4=24 7*4=28 8*4=32 9*4=36
1*5=5 2*5=10 3*5=15 4*5=20 5*5=25 6*5=30 7*5=35 8*5=40 9*5=45
1*6=6 2*6=12 3*6=18 4*6=24 5*6=30 6*6=36 7*6=42 8*6=48 9*6=54
1*7=7 2*7=14 3*7=21 4*7=28 5*7=35 6*7=42 7*7=49 8*7=56 9*7=63
1*8=8 2*8=16 3*8=24 4*8=32 5*8=40 6*8=48 7*8=56 8*8=64 9*8=72
1*9=9 2*9=18 3*9=27 4*9=36 5*9=45 6*9=54 7*9=63 8*9=72 9*9=81
+++++++++++++++++++++++++++++++++++++++++++
예제4)
---------- Run ----------
1
2
3
4
5
6
7
8
9
10
++++++++++++++++++++++++++++++++++++++++
예제5)
---------- Run ----------
99
30
71
66
77
3
95
29
0
29
탈출...
합=499