Lunes, Agosto 19, 2013

LabExer#7

7. Write a program that sums the integers from 1 to 50. The class name is Sum50.
Sample Run :
Sum numbers from 1 to 50: 1275




import java.util.Scanner;

public class Sum50 {

    public static void main(String[] args) {
        Scanner amante=new Scanner(System.in);
               
        int a=0,c=0;
           
        for(int i=0;i<=50;i++){
            c=c+i;       
        }   
        System.out.println(c);   
    }
}




Walang komento:

Mag-post ng isang Komento