Advertisement
sergAccount

Untitled

Jun 26th, 2021
836
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.80 KB | None | 0 0
  1. /*
  2.  * To change this license header, choose License Headers in Project Properties.
  3.  * To change this template file, choose Tools | Templates
  4.  * and open the template in the editor.
  5.  */
  6. package com.mycompany.ex11;
  7.  
  8. /**
  9.  *
  10.  * @author student
  11.  */
  12. public class Main {
  13.    
  14.     public static void main(String[] args) {                
  15.         // 6) do-while  
  16. //        int n = 10;
  17. //        do {
  18. //            System.out.println("n=" + n);
  19. //            n--;
  20. //        } while (n>10);
  21.        
  22.         // операторы управления: if-else, for, while, do-while, break, continue      
  23.         // Операторы сравнения: > < <= >= == !=        
  24.         int x = 0;
  25.         if(x==0){
  26.             System.out.println("x равен 0!");
  27.         }    
  28.         if(x!=5){
  29.             System.out.println("x не равен 5!");
  30.         }
  31.         /*
  32.         Задача1
  33.         Заданы переменные x1, x2.  
  34.         Присвоить значения данным переменным
  35.         типа int.
  36.         Вывести все значение между x1 и x2 включтельно
  37.         кроме числа 0.
  38.         */
  39.         // 1.1 - используем оператор continue
  40.         System.out.println("Задача1");
  41. //        int x1 = -5, x2 = 5;
  42. //        for (int i = x1; i <= x2; i++) {
  43. //             if (i==0){
  44. //                 continue;
  45. //             }            
  46. //             System.out.println(i);
  47. //        }
  48.         // 1.2 - используем только условный оператор
  49.         int x1 = -5, x2 = 5;
  50.         for (int i = x1; i <= x2; i++) {
  51.              if (i!=0){
  52.                  System.out.println(i);
  53.              }                        
  54.         }
  55.     }    
  56. }
  57.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement