Essays.club - Получите бесплатные рефераты, курсовые работы и научные статьи
Поиск

Задачи по "Программированию"

Автор:   •  Февраль 23, 2020  •  Задача  •  4,303 Слов (18 Страниц)  •  273 Просмотры

Страница 1 из 18

1. Маємо два вирази: а) A=X + Y – 2/2 + Z; б) A=X + (Y – 2)/(2 + Z). Скласти дві програми з включенням кожного із виразів і перевірити результат дії кожної програми. 

Текст програми:

import java.util.Scanner;

public class Prog1 {

                static int x;

                static int y;

                static int z;

                static int a;

                

                public static void main(String[] args)

                {

                Scanner in = new Scanner(System.in);

                System.out.println("Введіть змінну x: ");

                x=in.nextInt();

                System.out.println("Введіть змінну y: ");

                y=in.nextInt();

                System.out.println("Введіть змінну z: ");

                z=in.nextInt();

                if(x>y)        

                a=x+y-2/2+z;

                else

                a=x+(y-2)/(2+z);        

                System.out.println("A= "+a);

                }

        

}

2. Перенести методи: а) static int ternary(int i) {return i < 10 ? i*100; i*10;} б) static int alternative(int i) {if (i<10) return i*100;else i*10;} у програму, яка працює, і виконати її.

Текст програми:

public class Prog2 {

        static int ternary(int i)

        {

                return i < 10 ? i*100:i*10;

        }

        static int alternative(int i)

         {if (i<10)

         return i*100;

         else 

         return i*10;

         }

        public static void main(String[] args)

        {

                System.out.println(ternary(5));

                System.out.println(alternative(11));

        }

         

}

}

3. Перенести методи: а) static int test(int testval, int target) { int result = 0; if (testval > target) result = +1; else if (testval < target) result = -1; else result = 0; return result;} б) static int test(int testval, int target) { int result = 0; if (testval > target) result = +1; else if (testval < target) result = -1; else return 0;} у програму, яка працює, і виконати її.

Текст програми:

public class Prog3 {

        static int test(int testval, int target) {

                int result = 0;

                if (testval > target)

                        result = +1;

                else if (testval < target)

                        result = -1;

                else result = 0;

                return result;}

        static int test1(int testval, int target) {

                int result = 0;

                if (testval > target)

                        result = +1;

                else if (testval < target)

...

Скачать:   txt (11.7 Kb)   pdf (168.2 Kb)   docx (17 Kb)  
Продолжить читать еще 17 страниц(ы) »
Доступно только на Essays.club