How to Add Two Numbers in Dart (With Example Code)


 


INTRODUCTION

This tutorial and code sample will help you understand how to add 2 numbers using Dart Programming Language. This is a good first start for newbies. 

This code is intended for beginners  in Dart Programming Language. The code will help you have a good understanding of Dart Programing

CODE SAMPLE

void main(){

    int first_number=10;

    int second_number=33;

    int sum=first_number + second_number;

    print("The sum of {first_number} and {second_number} is {sum}");

}

EXPLANATION

Line 1 is the main method which serves as an entry point for the program.

Line 2 declare the variable first_number with the data type int and assigned the value 10 to it.

Line 3 declare the variable second_number with the data type int and assigned the value 33 to it.

line 4 will sum the value assigned to first_number and second_number and store it in sum. 

Line 5 will display the value of the first number and the second number then the result. Example: The sum of 10 and 33 is 43

TRY IT YOURSELF

Write a program that add the number 78 with 44. You can post your solution in the comment section below.

CONCLUSION

The tutorial taught you how to write a simple dart program to add 2 numbers. The program is meant for any beginner in Dart program. The tutorial also showcase a code snippet, explanation on what every line does and finally a question you can try yourself.

Ameh Joseph Onyeke

Hello and welcome to my blog! My name is Ameh Joseph Onyeke a passionate educator and tech enthusiast with a BSc in Computer Science from Benue State University, a PGDE from the University of Maiduguri, and a Master’s in Software Engineering from Bayero University Kano. My journey blends a strong foundation in computing with a love for teaching, aiming to simplify complex tech concepts for learners at all levels. Through this blog, I provide answers and insights across 10+ programming languages to support students and tech enthusiasts in building their skills and confidence. Whether you're solving coding problems or sharpening your programming abilities, this blog is here to guide you. Let’s learn and grow together!

Post a Comment

Previous Post Next Post