Posted by: Sourav | August 4, 2015

A simple assignment solved in Java


Check for numbers like 59

59=(5*9)+(5+9)

import java.io.*;
class sample{
public static void main(String args[]) throws IOException
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));

System.out.println(“Enter Number”);
int n=Integer.parseInt(br.readLine());
//System.out.println(n);

int p=1,q=0;
while(n>0)
{
p=p*(n%10);
q=q+(n%10);
n=n/10;

}
System.out.println(p+q);

}
}

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

Categories

%d bloggers like this: