import java.util.Scanner;
class Main {
public static void main(String[] args)
{
Scanner input = new Scanner (System.in);
System.out.println ("Let's play the lottery!");
System.out.println ("Enter an integer from 0 to 100");
boolean won = false;
int x = 0;
x = input.nextInt ();
if (x > 100)
{
System.out.println ("You entered a number outside the specified limits!");
System.out.println ("Enter a new number");
x = input.nextInt ();
}
if (x < 0)
{
System.out.println ("You entered a number outside the specified limits!");
System.out.println ("Enter a new number");
x = input.nextInt ();
}
if (x == 10)
{
System.out.println ("You are lucky. You won 100$");
won = true;
}
if (x == 50)
{
System.out.println ("Luck is always with you. You won 10$");
won = true;
}
if (x == 99)
{
System.out.println ("Good job. You won 50$");
won = true;
}
if (x == 1)
{
System.out.println ("The winning is 20$");
won = true;
}
if (!won)
{
System.out.println("You are not lucky. Try next time");
}
System.out.println ("End!");
}
}
Объяснение:
Программа на языке Паскаль:
{Free Pascal Compiler version 3.0.4+dfsg-23 [2019/11/25] for x86_64}
{Copyright (c) 1993-2017 by Florian Klaempfl and others}
{Target OS: Linux for x86-64}
program test;
var
X : array [1..5] of integer; {массив из 5 элементов}
i : integer; {Счётчик цикла}
d : integer; {Произведение положительных}
L : integer; {Количество отрицательных и нулей}
begin
{Ввести таб Х[1:5]}
write('Введите 5 чисел в массив Х: ');
for i := 1 to 5 do read(X[i]);
d := 1;
L := 0;
for i := 1 to 5 do
if (x[i] > 0) then
d := d * x[i]
else
L := L + 1;
{Вывести d, L}
writeln('Произведение d = ', d);
writeln('Количество отрицательных - ', L)
end.
Program JolieWErnAje;
uses crt;
const n=10;
var
a:array[1..n,1..n] of integer;
i,j: integer;
tp: integer;
begin
writeln('*** alphaues is thinking... ***');
writeln('*** OK ***');
writeln();
tp:=1;
randomize;
for i:=1 to n do
begin
for j:=1 to n do
begin
a[i,j]:= random(20)+1; {заполняем массив}
write(a[i,j]:4);
if a[i,j] mod 3 = 0 then tp:=tp*a[i,j];
end;
writeln();
end;
writeln();
writeln('Произведение элементов, кратных 3, равно ',tp)
end.