λ°μν
λ¬Έμ
Javaμνλ¬Έμ λ₯Ό μ±μ νκ³ μλ€.
λ¬Έμ λ§λ€ ‘o’ λλ ‘x’λ‘ νμκ° λμ΄ μλλ° μ μλ₯Ό 맀기λ λ°©μμ΄ νΉμ΄νλ€.
‘o’λ μ μκ° λμ λλ λ°©μμΌλ‘ μ±μ λλλ° μ΄μ λΆν° μμ μ ν¬ν¨ν μ°μλ
‘o’μ κ°μ λ§νΌμ μ μλ‘ μ±μ μ΄ λ©λλ€. μλ₯Ό λ€μ΄ ‘oooxoo’λΌλ νμκ°
μλ€λ©΄ μμλλ‘ 1+2+3+0+1+2=9 μΌλ‘ μ΄μ μ΄ κ³μ°λ©λλ€. νμμ΄ νΌ μνμ§μ
μ λ΅, μ€λ΅ μ¬λΆκ° νμλμ΄ μμ λ μ΄μ μ ꡬνλ νλ‘κ·Έλ¨μ μμ±νμΈμ.
λͺ©ν
μ½λ
package JavaFestival;
import java.util.Scanner;
public class test6 {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc = new Scanner(System.in);
System.out.println("==== μ±μ νκΈ° ====");
String sheet = "oooxoo";
int score = 0;
int cnt = 1;
for(int i = 0; i < sheet.length();i++) {
//System.out.println(i); κ° : 6
switch(sheet.charAt(i)){
case 'o' : score += (cnt++);
break;
case 'x' : score += 0;
cnt = 1;
break;
}
}
System.out.println(score);
}
}
package JavaFestival;
import java.util.Scanner;
public class test6 {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc = new Scanner(System.in);
System.out.println("==== μ±μ νκΈ° ====");
String sheet = "oooxooxooooxooxoxoooooo";
int score = 0;
int cnt = 1;
for(int i = 0; i < sheet.length();i++) {
//System.out.println(i); κ° : 6
switch(sheet.charAt(i)){
case 'o' : score += (cnt++);
break;
case 'x' : score += 0;
cnt = 1;
break;
}
}
System.out.println(score);
}
}
κ²°κ³Ό
==== μ±μ νκΈ° ====
22
==== μ±μ νκΈ° ====
44
λ°μν