Minggu, 24 April 2011

mencari jumlah pada for

inputan

public class dhiika{
    public static void main (String [] args){
       int a = 0;
       for (int i = 1; i<6; i++){
           int j= i*2;
           System.out.print(j+"+");

           a= a+j;
           if (j == 10){
               System.out.print(" = ");
               System.out.print (a);}
           }
       }}





outputnya 

2+4+6+8+10+ = 30

chatme


ShoutMix chat widget