Advertisement
Jaagdish47

Practical 1. Features of dart language

Nov 24th, 2024
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Dart 1.61 KB | Source Code | 0 0
  1. //1A. Program to demonstrate the features of Dart language.
  2.  
  3. void main() {
  4.   int num1 = 10;
  5.  
  6.   double num2 = 10.1;
  7.   bool num3 = true;
  8.  
  9.   String str1 = 'Hello Jagdish!\n';
  10.  
  11.   print(num1);
  12.   print(num2);
  13.   print(num3);
  14.   print(str1);
  15. }
  16.  
  17. //1B.Different Types of operators
  18. void main() {
  19.   int a = 2;
  20.   int b = 3;
  21.  
  22.   var c = a + b;
  23.   print("Summ of a and b : $c");
  24.  
  25.   var d = a - b;
  26.   print("Difference of a and b : $d");
  27.  
  28.   var e = -d;
  29.   print("The negation of difference between a and b : $e");
  30.  
  31.   var f = a * b;
  32.   print("Product of a and b : $f");
  33.  
  34.   var g = b / a;
  35.   print("Quotient of b and a : $g");
  36.  
  37.   var h = b ~/ a;
  38.   print("Quotient of a and b (integer division) : $h");
  39.  
  40.   var i = b % a;
  41.   print("Remainder of b divided by a : $i");
  42. }
  43.  
  44. //1C. Decision making operators?
  45. void main() {
  46.   var marks = 74;
  47.   if (marks >= 85) {
  48.     print("Excellent!\n");
  49.   } else if (marks >= 75) {
  50.     print("Good!\n");
  51.   } else if (marks >= 65) {
  52.     print("Better!\n");
  53.   } else {
  54.     print("Average!\n");
  55.   }
  56. }
  57.  
  58. //1D.Factorial Function
  59. void main() {
  60.   print(factorial(6));
  61. }
  62.  
  63. factorial(number) {
  64.   if (number <= 0) {
  65.     return 1;
  66.   } else {
  67.     return number * factorial(number - 1);
  68.   }
  69. }
  70.  
  71. //1E.Defining class
  72. class Student {
  73.   var stdName;
  74.   var stdAge;
  75.   var stdRoll_no;
  76.  
  77.   showStdInfo() {
  78.     print("Student Name is : ${stdName}");
  79.     print("Student Age is : ${stdAge}");
  80.     print("Student Roll No is : ${stdRoll_no}");
  81.   }
  82. }
  83.  
  84. void main() {
  85.   var std = new Student();
  86.   std.stdName = "Jagdish!";
  87.   std.stdAge = 20;
  88.   std.stdRoll_no = 242551;
  89.   std.showStdInfo();
  90. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement