Computer Science, asked by jeevanrajak8059, 1 year ago

Program for sum of natural numbers in object oriented programming

Answers

Answered by frederick
2

Java is also an object oriented programming language. So i am going to wirite the code in java

The code starts here:

import java.util.Scanner;

class q

{

 void main()

{

System.out.println("Enter your first natural number :");

int n1 = new Scanner(System.in).nextInt();

System.out.println("Enter your second natural number :");

int n2 = new Scanner(System.in).nextInt();

if(n1==0 && n2==0)

{

System.out.println("0 is not a natural number");

}

else

{

int n3 = n1+n2;

System.out.println("Their sum is :" + n3);

}

}

}

// Please mark as Brainliest Answer

Similar questions