Tutorialspoint

Sample Dart Online Program

/* Simple Hello, World! program */
void main(){
   print("Hello, World!");
}

String trim() Method in Dart

void main() { 
   String str1 = "hello"; 
   String str2 = "hello   world   "; 
   String str3 = "    hello"; 
   print(str1.trim()); 
   print(str2.trim()); 
   print(str3); 
}

Execute DART Online

abstract class Person {
    String _name;
  
    void greet();
  
    void walk();
  
    void eat() {
      print('人得吃饭');
    }
  }

  class Teacher implements Person {
    @override
    void greet() {
        print('gren');
    }
  
    @override
    void walk() {}
  
    @override
    void eat() {}
  
    @override
    get _name => '';
  
    @override
    set _name(String __name) {
      _name = __name;
    }
  }
void main(){
    Teacher ter = Teacher();
    
    
}

test

/* Simple Hello, World! program */
void main(){
   print("Hello, World!");
}

Execute DART Online

/* Simple Hello, World! program */
void main(){
    var b=123;
    String s="shafizadeh";
    int x=12;
    dynamic a;
    a="salam";
    a=123;
    a=false;
    a=12e-3;
    
    const y=3.14;
    var z=const[3,2,1];
    
    int hex=0xABEDA;
    
    var one=int.parse("33");
    
    String pi=3.1415.toStringAsFixed(2);
    
    var list=[1,2,3];
    print(list[2]);
    list[1]=5;
    print(list);
    
    list.add(10);
    print(list);
   print("Hello, World!");
   print("$pi");
   print("$s $a $b $x $y $z $hex ${a*y} $one");
}

test2

void main() {
  var s = '''<a id="courseName" class="sg-font-larger" href="javascript:SunGard.Hac.Home.ViewClassPopUp(3415315, 4, '/HomeAccess/Content/Student/ClassPopUp.aspx');">AP Human Geog- Grade 9 S2</a>
  <a id="courseName" class="sg-font-larger" href="javascript:SunGard.Hac.Home.ViewClassPopUp(3415315, 4, '/HomeAccess/Content/Student/ClassPopUp.aspx');">Soccer</a>
    <a id="courseName" class="sg-font-larger" href="javascript:SunGard.Hac.Home.ViewClassPopUp(3415315, 4, '/HomeAccess/Content/Student/ClassPopUp.aspx');">Physics</a>
''';
  String regex = "<a.*courseName.*>(.+?)</a>";
  RegExp regExp = new RegExp(regex);
Iterable<Match> matches = regExp.allMatches(s);
for (Match match in matches) {
  print("${match.group(1)}\n");
 }
}

//<a id.*courseName*.*?</a
//(?<=\()(.+?)(?=\))

hiiiiiiii

main() { 
   print("Hello World!hiiii"); 
}

Dart Programming - Example Program

void main() { 
   print('hello world'); 
}

expression_evaluation

import 'dart:io';
void main()
{
    double first, second, result;
    print("Enter the Expression:");
    String exp = stdin.readLineSync();
    exp = exp.trim();
    print(exp);
    Label1:
    for(int i=0;i<exp.length;i++)
    {
        if(exp[i]=='(')
        {
            exp = brac(exp);
        }
        continue Label1;
    }
    Label2:
    for(int i=0;i<exp.length;i++)
    {
        if(exp[i]=='/')
        {
            exp = spli(exp,'/');
        }
        continue Label2;
    }
    Label2:
    for(int i=0;i<exp.length;i++)
    {
        if(exp[i]=='*')
        {
            exp = spli(exp,'*');
        }
        continue Label2;
    }
    Label2:
    for(int i=0;i<exp.length;i++)
    {
        if(exp[i]=='+')
        {
            exp = spli(exp,'+');
        }
        continue Label2;
    }
    Label2:
    for(int i=0;i<exp.length;i++)
    {
        if(exp[i]=='-')
        {
            exp = spli(exp,'-');
        }
        continue Label2;
    }
    var ops =['+','-','*','/','%'];
    for(int i=0;i<exp.length;i++)
    {
      if(ops.contains(exp[i])) 
        exp = fin(exp);  
    }
    print(exp);  
}    

String fin(String exp)
 {
    int i1,i2,i3;
    String n1,n2,nu ='',ope;
    var nums = ['1','2','3','4','5','6','7','8','9','0'];
    var ops =['+','-','*','/','%'];
    for(int i=0;i<exp.length;i++)
    {
      if(nums.contains(exp[i]))  
      {
          nu = nu + exp[i];
      }
      else if(ops.contains(exp[i]))
      {
          ope = exp[i];
          n1=nu;
          nu ='';
      }
    }
    n2 = nu;
    i1 = int.parse(n1);
    i2 = int.parse(n2);
    i3 =calc(i1,i2,ope);
    exp = i3.toString();
    return exp;
 }  
    
String brac(String e)
{
    int st=0,ed=0;
    for (int i=0;i<e.length; i++)
    {
        if(e[i]=='(')
        {
            st=i;
            continue;
        }
        if(e[i]==')')
        {
            ed=i;
            break;
        }
        
    }
    st=st+1;
    var s = e.substring(st,ed);
   var number='',num1,num2,oper;
    int a,b;
   var numli = ['1','2','3','4','5','6','7','8','9','0'];
   var op =['+','-','*','/','%'];
    for(int i=0;i<s.length;i++)
    {
      if(numli.contains(s[i]))  
      {
          number = number + s[i];
      }
      else if(op.contains(s[i]))
      {
          oper = s[i];
          num1=number;
          number ='';
      }
    }
    num2 = number;
    a = int.parse(num1);
    b = int.parse(num2);
    int c =calc(a,b,oper);
    String s2=c.toString();
    e = e.replaceAll('('+s+')',s2);
    return e;
}

String spli(String s,String operate)
    {
        var nu='',num1,num2,oper='',nu1='',nu2='';
        int a,b,pt=0;
        var numli = ['1','2','3','4','5','6','7','8','9','0'];
        int p,l;
        lable:
        for(int i=0;i<s.length;i++)
         {
            if(s[i]==operate)
            {
                for(int j=i-1;j>=0;j--)
                {
                    if(numli.contains(s[j]))
                    {
                        nu1 =nu1 +s[j];
                        p=j;
                    }
                    else
                        break;
                }
                for(int k=i+1;k<s.length;k++)
                {
                    if(numli.contains(s[k]))
                    {
                        nu2 =nu2 +s[k];
                        l=k;
                        
                    }
                    else
                        break;
                }
                
                 var n1='';
                for(int i=nu1.length-1;i>=0;i--)
                {
                  n1=n1+nu1[i];  
                }
                int res;
                int val1=int.parse(n1);
                int val2=int.parse(nu2);
                if(operate=='/')
                    res = val1 ~/ val2;
                else if(operate=='*')
                    res = val1 * val2;
                else if(operate=='+')
                    res = val1 + val2;
                else if(operate=='-')
                   res = val1- val2;
                String su = s.substring(p,l+1);
                s=s.replaceAll(su,res.toString());
                return s;
            }
            continue lable;
        }
    }

int calc(int a, int b, String oper)
{
    int result;
    switch(oper)
    {
        case '+':
            return a + b;
            break;
        case '-':
            return a - b;
            break;
        case '*':
            return a * b;
            break;
        case '/':
            return a ~/ b;
            break;
        case '%':
            return a % b;
            break;
        default:
            return 0;
    }
}

Basic_arithmatic

class calculation
{
  double c;
  void add(double a, double b)
  {
    c = a+b;
    print('The Result of Addition operation is: $c');
  }
  void sub(double a, double b)
  {
    c = a-b;
    print('The Result of Subtraction operation is: $c');
  }
  void mul(double a, double b)
  {
    c = a*b;
    print('The Result of Multiplication operation is: $c');
  }
  void div(double a, double b)
  {
    c = a/b;
    print('The Result of Division operation is: $c');
  }
  void rem(double a, double b)
  {
    c = a%b;
    print('The Result of Remainder operation is: $c');
  }
}
main()
{
  calculation c = new calculation();
  c.add(8,3.4);
  c.sub(8,3.4);
  c.mul(8,4);
  c.div(15,2);
  c.rem(29,7);
}

1 2 3 4 5 6 7 ... 21 Next
Advertisements
Loading...

We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy.