Search
 
SCRIPT & CODE EXAMPLE
 

DART

prime number checker dart

import 'dart:io';

void main() {
  stdout.write("Please give us a number: ");
  int chosenNumber = int.parse(stdin.readLineSync());

  checkPrime(chosenNumber);
}

void checkPrime(int number) {
  // List comprehensions
  List<int> a = [
    for (var i = 1; i <= number; i++)
      if (number % i == 0) i
  ];

  // Check for prime
  a.length == 1
      ? print("The chosen number is a prime")
      : print("The chosen number is not a prime");
}
Comment

Get Prime Number in dart

     var newArray = List.generate(10000, (index) => index);
 List b=[];


      void checkPrime(int num){
        int i,m=0,flag=0;
        m=num~/2;
        for(i = 2;i<=m;i++){
          if(num%i == 0){
            flag=1;
            break;
          }
        }
        if(flag==0){
          b.add(num);
          // print('num $num');
        }}
        
        
     for(int i=1;i<newArray.length; i++){
      checkPrime(newArray[i]);
     }


     print(b);
Comment

PREVIOUS NEXT
Code Example
Dart :: rectangualr fab in flutter 
Dart :: Flutter Rendering Widgets Using JSON Data 
Dart :: flutter pop to index 1 
Dart :: vxstate listen not working flutter 
Dart :: Remove space between widgets in row flutter 
Dart :: extract common elements from lists dart 
Dart :: const issue on new flutter version 
Dart :: convert string date in Format yyyyMMddHHmmss to DateTime dart 
Dart :: dart add list to list 
Dart :: flutter colour hex 
Swift :: on swipe get contentoffset swift collectionview 
Swift :: How do I check if a string contains another string in Swift 
Swift :: swift stackview content inset 
Swift :: print document directory path swift 
Swift :: custom screen presentation controller coner radius swift 
Swift :: date formatter swift 
Swift :: how to find uibutton title text 
Swift :: iOS 10.3.1 Simulator manually 
Swift :: how to play a video in swift 
Swift :: swift change status bar color 
Swift :: post API Call in swift 
Swift :: and in swift4 
Swift :: get day difference between two dates swift 
Swift :: swift date to string 
Swift :: swift string time to epoch 
Swift :: how to set the font of text in swiftui 
Swift :: how can i find range of a string in another string swift 
Swift :: Play Video in AVPlayer ViewController Sample Code Swift 
Swift :: convert secondsfrom1970 to date swift 
Swift :: Swift Handling Errors Using do-catch Statement 
ADD CONTENT
Topic
Content
Source link
Name
6+3 =