Score (JAVA language)

Package Chapter 3 Exercises;
/*
 * Give a string composed of O and X (length 1~80), and count the scores.
 * The score of each O is the number of Os that appear in a row, and the score of X is 0.
 * For example, the score of OOXXOXXOOO is
 * 1+2+0+0+1+0+0+1+2+3
 */
import java.util.*;
public class score {


public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner in=new Scanner(System.in);
String s=in.next();
int sum=0;
int O=0;
for(int i=0;i<s.length();i++) 
{
if(s.charAt(i)=='X') {
sum+=0;
O=0;
}
if(s.charAt(i)=='O') {
O++; sum+=O; } if(i==0) { System.out.print(O); }






else {
System.out.print("+"+O);
}
} } }




Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325745387&siteId=291194637