fs.writeFile("hello.txt", "Hello мир!", function(error){
if(error) throw error; // если возникла ошибка
console.log("Асинхронная запись файла завершена. Содержимое файла:");
let data = fs.readFileSync("hello.txt", "utf8");
console.log(data); // выводим считанные данные
});
$items_set = array();
foreach ( $items as $item_id => $item ) {
for ( $i = 0; $i < $item['chance']; $i ++ ) {
$items_set[] = $item_id;
}
}
$rand_id = $items_set[array_rand( $items_set )];
$rand_item = $items[$rand_id];
return $rand_item["id"];
SqlDataReader reader = command.ExecuteReader();
while (reader.Read())
{
Console.WriteLine(String.Format("{0}", reader[0]));
}
[System.Serializable]
string json = JsonUtility.ToJson(classData);
System.IO.File.WriteAllText("json.json", json);
sw.WriteLine(text);
sw.WriteLine(string.join(Environment.NewLine, text));
case 1:
chose = int_;
break;
case 2:
chose = double_;
break;
case 3:
chose = float_;
break;
case 4:
chose = long_;
break;
case 5:
chose = char_;
break;
#include <iostream>
#include <string>
using namespace std;
enum Chose { int_, double_, float_, long_, char_ };
template<typename Tn, typename Tp>
Tn Power(Tn n, Tp p) {
Tn result = 1;
for (int i = 0; i < p; i++)
{
result = result * n;
}
return result;
}
template<typename Tn, typename Tp>
void UserInput() {
Tn power = 1;
Tp number = 1;
cout << "Введите число: ";
cin >> number;
cout << "Введите степень: ";
cin >> power;
Tn result = Power(number, power);
cout << "Result: " << result << endl;
}
int main()
{
setlocale(LC_ALL, "russian");
Chose chose;
int chose_;
cout << "Выберите действие: ";
cin >> chose_;
switch (chose_)
{
case 1:
UserInput<int, int>();
break;
case 2:
UserInput<double, int>();
break;
case 3:
UserInput<int, float>();
break;
case 4:
UserInput<int, long>();
break;
case 5:
UserInput<double, char>();
break;
}
system("pause");
}
public class Item
{
public Item(string name, int id, double cost)
{
Name = name;
Id = id;
Cost = cost;
}
public string Name { get; set; }
public int Id { get; set; }
public double Cost { get; set; }
public override string ToString()
{
return $"Id: {Id}, Name: {Name}, Cost: {Cost}";
}
}
static void Main(string[] args)
{
var findName = "Ball";
var items = new List<Item>
{
new Item("Ball", 10, 3),
new Item("Toy", 14, 15)
};
var item = items.FirstOrDefault(product => product.Name.Contains(findName));
if (item != null)
{
item.Cost = 100;
item.Id = 999;
}
Console.WriteLine(string.Join(Environment.NewLine, items));
Console.ReadKey();
var text = Console.ReadLine();
var textArray = text?.ToCharArray();
for (var i = textArray.Length - 3; i < textArray.Length; i++)
{
textArray[i] = char.ToUpper(textArray[i]);
}
Console.WriteLine(textArray);
Console.ReadKey();
var text = Console.ReadLine();
var textArray = text?.ToCharArray();
textArray = textArray.Take(textArray.Length - 3).Concat(textArray.Skip(textArray.Length - 3).Select(char.ToUpper)).ToArray();
Console.WriteLine(textArray);
Console.ReadKey();
var elem = document.querySelector('#elem1');
var elem2 = document.querySelector('#elem2');
elem1.addEventListener('keyup', function() {
var elem1 = this.value;
if (elem1.length == 2) {
elem2.focus();
}
});
elem2.addEventListener('keyup', function() {
var elem1 = this.value;
if (elem1.length == 2) {
elem2.blur();
}
});
function middleOfThree(a, b, c) {
var array = [a, b, c];
array.sort((a, b) => a - b);
return array[1];
}
console.log(middleOfThree(5, 15, 18));
console.log(middleOfThree(20, 9, 31));
console.log(middleOfThree(20, 9, 12));
Console
15
20
12
</option>