Sikl ( for, for each) operatorlari sikllar



Download 0,81 Mb.
bet2/5
Sana23.07.2022
Hajmi0,81 Mb.
#841448
1   2   3   4   5
Bog'liq
2-Mavzu

public static void main(String[] args) {


  • Scanner in = new Scanner(System.in);

  • int aynigan = 1; // shartli ravishda shart tekshirish uchun shu qiymatlar kiritildi

  • int buzulgan = 2; // shartli ravishda shart tekshirish uchun shu qiymatlar kiritildi

  • for (int i = 1; i <= 10; i++) {

  • System.out.println(i+"-kartoshkani Holatini kiriting \n yaxshi bo'lsa 0 ni \n aynigan bo'lsa 1 mi \n buzulgan bo'lsa 2 ni ");

  • int kartoshkaHolati = in.nextInt(); //kartoshkani holatini ko'rsatuvchi qiymatlar

  • if (kartoshkaHolati == aynigan || kartoshkaHolati == buzulgan) {


  • System.out.println("Buzulgan joyi kesib tashlansin ");

  • }

  • System.out.println(i +"-kartoshka tozalandi \n");

  • }

  • System.out.println("10 ta kartoshka tozalandi");

  • }


  • }


    FOR
    Bu operatorda to’rttala sikl uchun hamjoy ajratib ko’rsatilgan.Pastda for
    operatorining umumiy ko’rinishi keltirilgan.
    for ( inisializasiya; yakunlash; iterasiya ) tana;
    Har qanday for operatori yordamida yozilgan sikl while ko’rinishida yoki teskari
    yozish mumkin.
    class ForDemo {
    public static void main(String args[]) {
    for (int i = 1; i <= 10; i++)
    System.out.println("i = " + i);
    } }
    Keyingi misolda – programma variantini,teskaridan sanab borish ko’rsatilgan:
    class ForTick {
    public static void main(String args[]) {
    for (int n = 10; n > 0; n--)
    System.out.println("tick " + n);
    } }

    Misol:

    class Months {


    static String months[] = {
    "January", "February", “March", "April", "May", "June", "July", "August",
    "September", "October", "November", "December" };
    static int monthdays[]= { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
    static String spring = "spring";
    static String summer = "summer";
    static String autumn = "autumn";
    static String winter = "winter";
    static String seasons[]={winter,winter,spring,spring, spring, summer,
    summer, summer, autumn, autumn, autumn, winter };
    public static void main(String args[]) {
    for (int month = 0; month < 12; month++) { System.out.println(months[month] + "
    is a " + seasons[month] + " month with " + monthdays[month] + " days.");
    }
    } }

    Dastur natijasi:

    С:\> Java Months
    January is a winter month with 31 days.
    February is a winter month with 28 days.
    March is a spring month with 31 days.
    April is a spring month with 30 days.
    May is a spring month with 31 days.
    June is a summer month with 30 days.
    uly is a summer month with 31 days.
    August is a summer month with 31 days.
    September is a autumn month with 30 days.
    October is a autumn month with 31 days.
    November is a autumn month with 30 days.
    December a winter month with 31 days.

    1 dan n gacha sonlarning 4-darajalarini hamda ularning yig’indisi va ko’paytmasini hisoblash dasturini tuzing.



    Download 0,81 Mb.

    Do'stlaringiz bilan baham:
  • 1   2   3   4   5




    Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©hozir.org 2024
    ma'muriyatiga murojaat qiling

    kiriting | ro'yxatdan o'tish
        Bosh sahifa
    юртда тантана
    Боғда битган
    Бугун юртда
    Эшитганлар жилманглар
    Эшитмадим деманглар
    битган бодомлар
    Yangiariq tumani
    qitish marakazi
    Raqamli texnologiyalar
    ilishida muhokamadan
    tasdiqqa tavsiya
    tavsiya etilgan
    iqtisodiyot kafedrasi
    steiermarkischen landesregierung
    asarlaringizni yuboring
    o'zingizning asarlaringizni
    Iltimos faqat
    faqat o'zingizning
    steierm rkischen
    landesregierung fachabteilung
    rkischen landesregierung
    hamshira loyihasi
    loyihasi mavsum
    faolyatining oqibatlari
    asosiy adabiyotlar
    fakulteti ahborot
    ahborot havfsizligi
    havfsizligi kafedrasi
    fanidan bo’yicha
    fakulteti iqtisodiyot
    boshqaruv fakulteti
    chiqarishda boshqaruv
    ishlab chiqarishda
    iqtisodiyot fakultet
    multiservis tarmoqlari
    fanidan asosiy
    Uzbek fanidan
    mavzulari potok
    asosidagi multiservis
    'aliyyil a'ziym
    billahil 'aliyyil
    illaa billahil
    quvvata illaa
    falah' deganida
    Kompyuter savodxonligi
    bo’yicha mustaqil
    'alal falah'
    Hayya 'alal
    'alas soloh
    Hayya 'alas
    mavsum boyicha


    yuklab olish