Java the sum of the numbers you enter

Posted: September 28, 2014 in Java
Tags:

Javada girdiğimiz n basamaklı bir sayının rakamlarını toplamaktadır.

public class JavaApplication29 {

public static void main(String[] args) {

System.out.println(“Enter the number “);
Scanner look=new Scanner(System.in);
bayram y=new bayram();
int x=look.nextInt();
System.out.println(“The sum of the numbers you enter : “+y.find(x));
}

}

class bayram {
public int find(int a)
{
int result=0;

while(a>=1)
{
result=(a%10)+result;

a=a/10;
}
return result;
}
}

14

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s