0% found this document useful (0 votes)
39 views1 page

Simple Dart Programming Exercises

The document contains a list of 25 practice questions for writing Dart programs. These exercises cover various programming concepts such as conditionals, loops, user input, data structures, and basic arithmetic operations. Each question aims to enhance the understanding and application of Dart programming language features.

Uploaded by

outlooksinet
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
39 views1 page

Simple Dart Programming Exercises

The document contains a list of 25 practice questions for writing Dart programs. These exercises cover various programming concepts such as conditionals, loops, user input, data structures, and basic arithmetic operations. Each question aims to enhance the understanding and application of Dart programming language features.

Uploaded by

outlooksinet
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

dart programs

Question For Practice


[Link] a dart program to check if the number is odd or even.
[Link] a dart program to check whether a character is a vowel or consonant.
[Link] a dart program to check whether a number is positive, negative, or zero.
[Link] a dart program to print your name 100 times.
[Link] a dart program to calculate the sum of natural numbers.
[Link] a dart program to generate multiplication tables of 5.
[Link] a dart program to generate multiplication tables of 1-9.
[Link] a dart program to create a simple calculator that performs addition,
subtraction, multiplication, and division.
[Link] a dart program to print 1 to 100 but not 41.
[Link] a program to print your name in Dart.
[Link] a program to print Hello I am “John Doe” and Hello I’am “John Doe” with
single and double quotes.
[Link] constant type of int set value 7.
[Link] a program in Dart that finds simple interest. Formula= (p * t * r) / 100
[Link] a program to print a square of a number using user input.
[Link] a program to print full name of a from first name and last name using user
input.
[Link] a program to find quotient and remainder of two integers.
[Link] a program to swap two numbers.
[Link] a program in Dart to remove all whitespaces from String.
[Link] a Dart program to convert String to int.
[Link] a list of names and print all names using list.
[Link] a set of fruits and print all fruits using loop.
[Link] a program thats reads list of expenses amount using user input and print
total.
[Link] an empty list of type string called days. Use the add method to add names
of 7 days and print all days.
Add your 7 friend names to the list. Use where to find a name that starts with
alphabet a.
[Link] a map with name, address, age, country keys and store values to it.
Update country name to other country and print all keys and values.
[Link] a map with name, phone keys and store some values to it. Use where to
find all keys that have length 4.

Common questions

Powered by AI

Generating multiplication tables for numbers 1 through 9 can be efficiently implemented using nested loops: an outer loop running from 1 to 9 and an inner loop for each multiplication. Ensuring correct and readable formatting might involve aligning columns, separating each table with a newline for clarity, and handling any exceptions that might disrupt execution. String interpolation can be beneficial for formatting the multiplication outcomes correctly .

The most straightforward method to swap two numbers in Dart involves using a temporary variable: `var temp = a; a = b; b = temp;`. Alternative approaches might include arithmetic operations like addition and subtraction, or bitwise XOR operations, although these are less common. Ensuring variable integrity during the swap process is crucial to avoid data loss or corruption, particularly if the numbers are references to larger data structures or carry critical data .

Maps in Dart provide a versatile way to store and retrieve key-value pairs, making them optimal for managing records. For updating name and address records, maps allow efficient access to values through their keys such as `map['name'] = 'New Name';`. The ability to iterate keys and values, along with tools like `update` and `putIfAbsent`, enhances flexibility in data management. Such structured data handling facilitates modifications and retrievals, key for maintaining updated and accurate records effortlessly .

To determine the quotient and remainder of two integers in Dart, you would use integer division and the modulus operation: `int quotient = num1 ~/ num2; int remainder = num1 % num2;`. Error handling is crucial here to manage scenarios like division by zero. Implementing try-catch blocks can capture any exceptions that arise, preventing crashes and providing informative feedback to the user about invalid inputs .

To design a Dart program that determines if a character is a vowel or consonant, you would first need to define a list of vowels (e.g., ['a', 'e', 'i', 'o', 'u', 'A', 'E', 'I', 'O', 'U']). The program should take a character input, check if the character is in the vowels list, and return the appropriate result. Challenges could include handling uppercase and lowercase letters, non-alphabetic characters, and cases where a single input might actually be a string. Ensuring robust input validation is crucial in this context to avoid unexpected errors .

When designing a simple calculator in Dart, it is essential to consider user input validation to handle unexpected values, such as non-numeric input or division by zero. The calculator should perform operations like addition, subtraction, multiplication, and division. Implementing modular functions for each operation can keep the program organized and maintainable. It's also important to ensure that results are formatted appropriately and that the program provides user-friendly error messages for invalid operations .

To remove all whitespaces in a string in Dart, one would typically employ the `replaceAll` method, using a whitespace regular expression: `string.replaceAll(RegExp(r'\s+'),'')`. Input validation involves ensuring that the input is a string and not null, which could be done by checking the input type and its value before processing. Performance concerns might arise with very large strings due to the overhead of regular expression processing, but this can be mitigated by optimizing the regex pattern used .

Input consistency ensures that the provided values for principal, time, and rate in a Dart application remain within reasonable bounds and appropriate types. Inconsistent or incorrect inputs such as negative values or invalid data types could lead to erroneous calculations and undermine program reliability. Enforcing input validation and consistency checks can prevent such issues, maintaining the correctness and reliability of the program’s financial computations .

One effective strategy is to use a loop that iterates from 1 to 100 and includes a conditional statement to skip printing number 41. A typical approach is using an if statement within a for loop: `for (int i = 1; i <= 100; i++) { if (i != 41) print(i); }`. This strategy efficiently skips the unwanted number but could lead to additional complexity if the range or exclusion list is expanded .

Dart provides a robust collection of methods for list management, including the `where` method, which can be particularly useful for searching. For example, to find a friend’s name starting with the letter 'A' in a list, you can use the following code: `friendsList.where((name) => name.startsWith('A')).toList();`. This creates a new list containing only the elements that meet the criteria. Using Dart’s built-in methods makes operations efficient and expressive, but it’s vital to ensure accurate initial capitalization checks or include a case-insensitive search option .

You might also like