Adding Two numbers using loop:

We are adding the two numbers using the loop.

this is the homework sum.

program:

class Add{

int add(){
int no=1234;
int a=0;
while(no>0){
int c =no%10;
a=a+c;
no=no/10;
}
System.out.println(“\n”+”Adding in between int “+a);

return (a);
}
public static void main(String args[]){
Add a=new Add();
a.add();
}

}

output:

sobhika@sobhika-HP-Laptop-15-db1xxx:~$ javac Add.java
sobhika@sobhika-HP-Laptop-15-db1xxx:~$ java Add

Adding in between int 10


Leave a comment

Design a site like this with WordPress.com
Get started