First, solve the problem. Then, write the code. ” - John Johnson

It's not at all important to get it right the first time. It's vitally important to get it right the last time. ” - Andrew Hunt and David Thomas

Wednesday, July 16, 2014

Pizza Cutting.

Name of programmer: Jisan
Programming language: Java
Difficulty: Easy
Status: Accepted
Problem number: UVA-10079
http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=1020

Code:

import java.util.*;
public class Uva_10079 {
    public static void main (String chayapoth[]){
        Scanner input = new Scanner(System.in);
        long pizza;
        while(input.hasNext()){
        long sum=1;
             long i=1;
        pizza=input.nextLong();
        if(pizza<0){
        break;
        }
            while(pizza>0){

                sum=sum+i;
                i++;
                pizza--;
            }
            System.out.println(sum);
         
        }
    }
}

No comments:

Post a Comment