Posts

Write a Dart program to compute the sum of two given integers, if two values are equal then return the triple of their sum

Image
Code: import   'dart:io' ; void   main () {   stdout. write ( 'Input first Number : ' );    int  num1 =  int . parse (stdin. readLineSync ());   stdout. write ( 'Input Second Number : ' );    int  num2 =  int . parse (stdin. readLineSync ());    if  (num1 == num2) {      print ((num1 + num2) *  3 );   }  else  {      print (num1 + num2);   } } Output:

Write a Dart program to check two given integers and return true if one is negative and one is positive

Image
Sample Output: Input first integer: -5 Input second integer: 25 Check if one is negative and one is positive: True Code: import   'dart:io' ; void   main () {   stdout. write ( 'Input first Number : ' );    int  num1 =  int . parse (stdin. readLineSync ());   stdout. write ( 'Input Second Number : ' );    int  num2 =  int . parse (stdin. readLineSync ());    if  (num1 !=  0  && num2 !=  0 ) {      print ( true );   } } Output:

Write a Dart program to create a new string from a given string (length 1 or more ) with the first character added at the front and back.

Image
Input a string: The quick brown fox jumps over the lazy dog. TThe quick brown fox jumps over the lazy dog.T Code: import   'dart:io' ; void   main () {   stdout. write ( 'Input string : ' );    String  word = stdin. readLineSync ();    String  result;   result = word[ 0 ] + word + word[ 0 ];    print (result); } Output:

Write a Dart program to create a new string from a given string where the first and last characters will change their positions.

Image
Test Data: Python Sample Output: nythoP Code: import   'dart:io' ; void   main () {   stdout. write ( 'Input word : ' );    String  word = stdin. readLineSync ();    String  result;   result = word[word.length -  1 ] + word. substring ( 1 , word.length -  1 ) + word[ 0 ];    print (result); } Output:

Write a Dart program remove specified a character from a non-empty string using index of a character.

Image
Code: import   'dart:io' ; void   main () {   stdout. write ( 'Input word : ' );    String  word = stdin. readLineSync ();   stdout. write ( 'index to be removed : ' );    int  index =  int . parse (stdin. readLineSync ());   word = word. substring ( 0 , index) + word. substring (index +  1 );    print (word); } Output:

Write a Dart program to convert from celsius degrees to Kelvin and Fahrenheit.

Image
Test Data: Enter the amount of celsius: 30 Expected Output: Kelvin = 303 Fahrenheit = 86 Conversion Values. Kelvin to Celsius : C = K - 273 (C = K - 273.15 if you want to be more precise) Kelvin to Fahrenheit : F = 9/5(K - 273) + 32 or F = 1.8(K - 273) + 32 Celsius to Fahrenheit : F = 9/5(C) + 32 or F = 1.80(C) + 32 Celsius to Kelvin : K = C + 273 (or K = C + 271.15 to be more precise) Fahrenheit to Celsius : C = (F - 32)/1.80 Fahrenheit to Kelvin : K = 5/9(F - 32) + 273.15 Code: import   'dart:io' ; void   main () {   stdout. write ( 'Input Temperature in celsius : ' );    int  celsius =  int . parse (stdin. readLineSync ());    double  kelvin = celsius. toDouble () +  273.0 ;    double  fahrenheit = (celsius *  1.80 ) +  32 ;    print ( 'Kelvin = '  + kelvin. toString ());    print ( 'fahrenheit = '  + fahrenheit. toString ()); } Output:

Write a Dart Program that takes a number as input and then displays a rectangle of 3 columns wide and 5 rows tall using that digit

Image
Enter a number: 5 Expected Output: 555 5 5 5 5 5 5 555 Code: import   'dart:io' ; void   main () {   stdout. write ( 'Input Number : ' );    int  x =  int . parse (stdin. readLineSync ());    for  ( int  i =  0 ; i <  5 ; i++) {      for  ( int  j =  0 ; j <  3 ; j++) {        if  (j %  2  ==  0  || i ==  0  || i ==  4 ) {         stdout. write (x);       }  else  {         stdout. write ( ' ' );       }     }      print ( '' );   } } Output:

Write a Dart program that takes an age (for example 20) as input and prints something as "You look older than 20".

Image
Code: import   'dart:io' ; void   main () {    print ( 'Input age : ' );    int  x =  int . parse (stdin. readLineSync ());    print ( 'You look older than $ x ' ); } Output: