Search

Kamis, 26 April 2012

Number of Runs with Java

Today I will share the basic programming the number of runs with java, I wish I could be useful for all who need friends.

import java.io.*;

class Number {
        public static void main(String[] args) throws IOException
    {
        System.out.print("Input Number:");
        String temp;
        int
result=0;
        int bil;
        int i=1;
       
        InputStreamReader isr = new InputStreamReader(System.in);
        BufferedReader br = new BufferedReader(isr);
       
        temp = br.readLine();
       
         try{
        bil=Integer.parseInt(temp);
        while(i<=bil){
            System.out.print(i);
            if(i!=bil){
                System.out.print("+");
               
            }
            else{
                System.out.print("=");
               
            }
            result+=i;
            i++;
        }
        System.out.println(
result);
        }
        catch(NumberFormatException nfe){
                System.exit(1);
        }
    }
}

Tidak ada komentar:

Posting Komentar