На C# вариант на кода:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class Program
{
static void Main()
{
int n = int.Parse(Console.ReadLine());
double kol = 0;
double gr = 0;
double allKol = 0;
double gradus = 0;
double allGr = 0;
double totalGr = 0;
for (int i = 1; i <= n; i++)
{
kol = double.Parse(Console.ReadLine());
gr = double.Parse(Console.ReadLine());
gradus = kol * gr;
allKol += kol;
allGr += gradus;
}
totalGr = allGr / allKol;
Console.WriteLine("Liter: {0:f2}", allKol);
Console.WriteLine("Degrees: {0:f2}", totalGr);
if (totalGr < 38)
{
Console.WriteLine("Not good, you should baking!");
}
else if (totalGr >= 38 && totalGr <= 42)
{
Console.WriteLine("Super!");
}
else if (totalGr > 42)
{
Console.WriteLine("Dilution with distilled water!");
}
}
}
Ето кода на java:
import java.util.Scanner; public class GrandpaStavri { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int n = Integer.parseInt(scanner.nextLine()); double kol = 0; double gr = 0; double allKol = 0; double gradus = 0; double allGr = 0; double totalGr = 0; for (int i = 1; i <= n; i++) { kol = Double.parseDouble(scanner.nextLine()); gr = Double.parseDouble(scanner.nextLine()); gradus = kol * gr; allKol += kol; allGr += gradus; } totalGr = allGr / allKol; System.out.printf("Liter: %.2f\n", allKol); System.out.printf("Degrees: %.2f\n", totalGr); if (totalGr < 38) { System.out.println("Not good, you should baking!"); } else if (totalGr >= 38 && totalGr <= 42) { System.out.println("Super!"); } else if (totalGr > 42) { System.out.println("Dilution with distilled water!"); } } }
Ето моето: https://pastebin.com/9gAexmRc
А има ли някой вариант за решение на тази задача с Javascript?
Неможаш ли да я преработиш в Java ?
Да се опитам ,ако искаш ? - само ми даи стоиности и какъв ще е резултата.