UVA 12403 – Save Setu

Simple .equals() with an if statement.

import java.io.PrintWriter;
import java.util.Scanner;

/**
 * 
 * @author Sanchit M. Bhatnagar
 * @see http://uhunt.felix-halim.net/id/74004
 * 
 */
public class P12403 {

  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    PrintWriter out = new PrintWriter(System.out);
    int T = sc.nextInt();
    int count = 0;
    while (T > 0) {
      if (sc.next().equals("donate")) {
        count += sc.nextInt();
      } else {
        out.println(count);
      }
      T--;
    }
    out.close();
    sc.close();
  }

}

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.