Javada nuqta rangini aniqlash funksiyasini misol yordamida tushuntirib bering



Download 79,63 Kb.
bet1/5
Sana18.02.2022
Hajmi79,63 Kb.
#453903
  1   2   3   4   5
Bog'liq
Misollar


  1. Javada nuqta rangini aniqlash funksiyasini misol yordamida tushuntirib bering.

  2. Javada ikki nuqta orasidagi kesma hosil qilish funksiyasini misol yordamida tushuntirib bering.

  3. Javada aylana hosil qilish funksiyasini misol yordamida tushuntirib bering.

  4. S=max(a,b,c)+min(a,b) ni hisoblash dasturini tuzing?

package com.company;

import java.util.Scanner;

public class Main {

public static void main(String[] args) {


Scanner x=new Scanner(System.in);
int a,b,c;
a=x.nextInt();
b=x.nextInt();
c=x.nextInt();
int S=Math.max(Math.max(a,b),c)+Math.min(a,b);
System.out.println(S);
}
}



  1. hisoblash dasturini tuzing.

package com.company;

import java.util.Scanner;

public class Main {

public static void main(String[] args) {


Scanner kirit=new Scanner(System.in);
int x; double S=0;
x=kirit.nextInt();
for (int j=1; j<10; j++){
S=S+Math.pow((Math.pow(x,j)+j),2);
System.out.println(S);
}
}
}



  1. Berilgan sonni juft yoki toq ekanligini aniqlash dasturini tuzing?

package com.company;

import java.util.Scanner;

public class Main {

public static void main(String[] args) {


Scanner x=new Scanner(System.in);
int a;
a=x.nextInt();
if(a%2==0) {
System.out.println("berilgan son juft son");
} else System.out.println("berilgan son toq son "); }
}



  1. hisoblash dasturini tuzing.

package com.company;

import java.util.Scanner;

public class Main {

public static void main(String[] args) {


Scanner x=new Scanner(System.in);
double S=0, P=1;
for (int i=1; i<10; i++){
for (int j=1; j<10; j++){
S=S+P*(Math.pow(Math.cos(i),2)+Math.pow(j,i));

}
}
System.out.println(S);


}
}



  1. Berilgan to’rt xonali sonlarning raqamlar yig’indisi va ko’paytmasini hisoblash dasturini tuzing?

package com.company;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner x=new Scanner(System.in);
int a,b,c,d,e; double S=0, P=1;
System.out.println("tort xonali sonni kiriting");
e=x.nextInt();
a=e/1000;
b=e%1000/100;
c=e%100/10;
d=e%10;
S=a+b+c+d;
P=a*b*c*d;
System.out.println(S);
System.out.println(P);
}
}



  1. (!a||!b)&&!(b||a) mantiqiy ifodani hisoblash dasturini tuzing?

import java.util.Scanner;

public class Main {

public static void main(String[] args) {
Scanner x=new Scanner(System.in);
boolean t, a=false,b=true;

t=(!a||!b)&&!(b||a);


System.out.println(t);
}
}



  1. hisoblash dasturini tuzing.

package com.company;

import java.util.Scanner;

public class Main {

public static void main(String[] args) {


Scanner kirit=new Scanner(System.in);
int x; double S=0, P=1;
x=kirit.nextInt();
for (int j=1; j<10; j++){
S=S+Math.pow(j,2)/P*j+j;
System.out.println(S);
}
}
}



  1. a,b,c kesmalar berilgan bu kesmalardan uchburchak yasash mumkin bo’lsa uchburchak yuzasini aks holda berilgan sonlar ko’paytmasini ekranga chiqaring

package com.company;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner x=new Scanner(System.in);
int a, b,c; double S, P;
a=x.nextInt();
b=x.nextInt();
c=x.nextInt();
if (a+b>c&&a+c>b&&c+b>a) {
P=(a+b+c)/2;
S=Math.sqrt(P*(P-a)*(P-b)*(P-c));
System.out.println(P*2);
System.out.println(S);
}
else System.out.println(" Uchburchak yasash mumkin emas");
}
}



  1. Berilgan x va a sonlarining umumiy bo’luvchilar yig’indisi va sonini aniqlash dasturini tuzing?




  1. n dan m gacha sonlar ichidan faqat x ga karralilarining yig’indisi aniqlash dasturini tuzing?

public static void main(String[] args) {
Scanner kirit = new Scanner(System.in);
int n, m, k;
double S = 0;
n = kirit.nextInt();
m = kirit.nextInt();
k = kirit.nextInt();
for (int i = n; i < m; i++) {
if (i % k == 0) {
S = S + i;
System.out.println(S);
} else System.out.println(" k ga karrali emas");} }}}



  1. Yoshi yillarda aniqlovchi 30-89 gacha butun son berilgan. Son kiritilganda unga mos so'zlarda ifodalovchi dastur tuzilsn. (“o’ttiz yosh”, “qirq uch yosh” va h.k.).

package com.company;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner kirit=new Scanner(System.in);
int n;
System.out.println("30-89 gacha butun son kiriting");
n=kirit.nextInt();
int onlar=n/10;
int birlar=n%10;
switch (onlar){
case 1: System.out.print("o`n"); break;
case 2: System.out.print("yigirma"); break;
case 3: System.out.print("o`ttiz"); break;
case 4: System.out.print("qirq"); break;
case 5: System.out.print("ellik"); break;
case 6: System.out.print("oltmish"); break;
case 7: System.out.print("yetmish"); break;
case 8: System.out.print("saskon"); break;
case 9: System.out.print("toqson"); break;
}
switch (birlar) {
case 1: System.out.print("bir"); break;
case 2: System.out.print("ikki"); break;
case 3: System.out.print("uch"); break;
case 4: System.out.print("tort"); break;
case 5: System.out.print("besh"); break;
case 6: System.out.print("olti"); break;
case 7: System.out.print("yetti"); break;
case 8: System.out.print("sakkiz"); break;
case 9: System.out.print("toqqiz"); break; default:System.out.print("busonlar ichida bunday son mavzjud emas"); } }
}



  1. (a&&!b)||(!a&&b) mantiqiy ifodani hisoblash dasturini tuzing?

import java.util.Scanner;

public class Main {

public static void main(String[] args) {
Scanner x=new Scanner(System.in);
boolean t, a=false,b=true;

t=(a&&!b)||(!a&&b);


System.out.println(t);
}
}

  1. Berilgan ikkita sonning umumiy bo’luvchilarini ekranga chiqarish dasturini tuzing?

package com.company;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner x=new Scanner(System.in);
int a,b,s;
a=x.nextInt();
b=x.nextInt();
if (a<=b){
s=b;
}
else s=a;
for (int i=1; i<=s; i++)
if(a%i==0 && b%i==0)
System.out.println(i);
}
}

  1. N (N>0) butun sonlari berilgan. Bitta ssikldan foydalanib quyidagi yig‘indini hisoblash dasturi tuzilsin:S=1+ 2/2!+ 3/ 3!+ ... +N/ N!

package com.company;

import java.util.Scanner;

public class Main {

public static void main(String[] args) {


Scanner kirit=new Scanner(System.in);
double S=0, P=1;
int n= kirit.nextInt();
for (int i=1; iP=P*i;
S=S+i/P;

System.out.println(S);}


}
}

  1. X haqiqiy soni berilgan. Quyidagi funksiya hisoblansin.

package com.company;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner kirit=new Scanner(System.in);
double x, y;
x= kirit.nextInt();
if(x<=0) {
y=Math.pow(x,2)-x-6;
}
else {
y=2*Math.sin(x)+Math.pow(x,2);
} System.out.println(y);}
}



  1. X xaqiqiy va N (N>0) butun sonlari berilgan. Quyidagi ifoda qiymatini hisoblash dasturi tuzilsin:-X/1!+ X2/2!- X3/ 3!+ ... +(-1)N XN/ N! (N!=1*2*…*N).

package com.company;

import java.util.Scanner;

public class Main {

public static void main(String[] args) {


Scanner kirit=new Scanner(System.in);
double x, y=0, p=1; int n;
n= kirit.nextInt();
x= kirit.nextInt();
for (int i=1; ip=p*i;
y=y+x*Math.pow(-1,i)/p;}
System.out.println(y); }
}



  1. Butun son berilgan. Berilgan sonni “musbat toq son”, “musbat juft son”, “manfiy juft son”, “manfiy toq son”, “son nolga teng” ekranga yozadigan dastur tuzilsin.

package com.company;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner x=new Scanner(System.in);
int a;
System.out.println("a=");
a= x.nextInt();
if(a>0 && a%2==0) {
System.out.println("Berilgan son musbat juft son");
}
if (a > 0 && a % 2 ==1) {
System.out.println("Berilgan son musbat toq son");
}
if (a < 0 && a % 2 == 0) {
System.out.println("Berilgan son manfiy juft son");
}
if (a < 0 ){
a=-a;
if (a%2==1)
System.out.println("Berilgan son manfiy toq son");
}
else
{System.out.println("Berilgan son 0 ga teng");

}


}
}



  1. Kun boshidan boshlab N sekund vaqt o‘tdi. Kun boshidan boshlab qancha to‘liq soat va minut o‘tganligini aniqlovchi dastur tuzilsin.

package com.company;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner x=new Scanner(System.in);
int a,b,n;
n= x.nextInt();
a=n/60;
b=n/3600;
System.out.println(a);
System.out.println(b);
}
}



  1. Berilgan sonning raqamlar ko’paytmasini hisoblash dasturi tuzilsin.

package com.company;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner x=new Scanner(System.in);
int n, S=0;
n=x.nextInt();
while(n>0) {
S=S+n%10;
n/=10;
}
System.out.println(S);
}

}



  1. A va B butun soni berilgan (A

package com.company;


import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner x=new Scanner(System.in);
int A,B;
System.out.println("AA=x.nextInt();
B= x.nextInt();
for (int i=A; i<=B; i++){
System.out.println(Math.pow(i,3));
}
}
}



  1. Koordinatalar sistemasida nuqtaning x, y qiymatlari berilgan. Nuqtaning koordinatalar sistemasining qaysi qismida joylashganligini aniqlash dasturini tuzing.

  2. package com.company;
    import java.util.Scanner;
    public class Main {
    public static void main(String[] args) {
    Scanner kirit=new Scanner(System.in);
    double x,y;
    x= kirit.nextDouble();
    y= kirit.nextDouble();
    if (x>0&&y>0) {
    System.out.println("Berilgan nuqta I chorokda joylashgan");
    }
    if (x<0&&y>0) {
    System.out.println("Berilgan nuqta II chorokda joylashgan");
    }
    if (x<0&&y<0) {
    System.out.println("Berilgan nuqta III chorokda joylashgan");
    }
    if (x>0&&y<0) {
    System.out.println("Berilgan nuqta IV chorokda joylashgan");
    }
    }
    }




  1. A va B butun sonlari berilgan (A

package com.company;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner x=new Scanner(System.in);
int A,B; double Y=0;
System.out.println("AA=x.nextInt();
B= x.nextInt();
for (int i=A; i<=B; i++){
System.out.println(Math.pow(i,A));
Y=Y+Math.pow(i,A);}
System.out.println((Y));

}
}


  1. funksiyani hisoblash dasturini tuzing.

package com.company;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner kirit=new Scanner(System.in);
int x; double y;
x= kirit.nextInt();
if (x<=0){
y=-Math.pow(x,2)+5;
} if (x>0&&x<2) {
y=Math.pow(x,2)+x-8;
}
else y=x+4;
System.out.println(y);

}
}


  1. funksiyani hisoblash dasturini tuzing.

package com.company;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner kirit=new Scanner(System.in);
int x; double y;
x= kirit.nextInt();
if(x<-2 || x>2) {
y=2*x-Math.sin(x);
}
else y=-3*x;
System.out.println(y);

}
}




  1. Musbat va haqiqiy a, b sonlari berilgan bo‘lsin. Tomonlari a va b bo‘lgan to‘g‘ri to‘rtburchakning tomonlar uzunliklari yig’indisi, yuzi va dioganalini hisoblash dasturini tuzing.

package com.company;
import java.util.Scanner;

public class Main {

public static void main(String[] args) {
Scanner x=new Scanner(System.in);
double a,b,S,P,d;
a=x.nextInt();
b= x.nextInt();
S=a*b;
P=2*(a+b);
d=Math.sqrt(Math.pow(a,2)+Math.pow(b,2));
System.out.println(S);
System.out.println(P);
System.out.println(d);
}
}



  1. Jumlani rostlikka tekshiring: “berilgan son musbat toq son”.

  2. Kun boshidan boshlab N sekund vaqt o'tdi. Kun boshidan boshlab qancha soat va minut o'tganligini aniqlovchi dastur tuzilsin.

package com.company;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner x=new Scanner(System.in);
int a,b,n;
n= x.nextInt();
a=n/60;
b=n/3600;
System.out.println(a);
System.out.println(b);
}
}



  1. hisoblash dasturini tuzing.

  2. package com.company;
    import java.util.Scanner;
    public class Main {
    public static void main(String[] args) {
    Scanner kirit=new Scanner(System.in);
    double x, y;
    x= kirit.nextInt();
    if(x<=0) {
    y=Math.pow(x,2)-6;
    }
    else {
    y= Math.pow(x,3)+Math.sin(x);
    } System.out.println(y);}
    }


  1. Bitta sikldan foydalanib quyidagi yig‘indini hisoblash dasturi tuzilsin: S=1!+ 2!+... + N!

package com.company;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner x=new Scanner(System.in);
int n; double S=0, P=1;
n=x.nextInt();
for (int i=1; iP=P*i;
S=S+P;
System.out.println(S);
}
}
}



  1. a dan b gacha x qadamli siklni tashkil qilishni tushuntirib bering?

package com.company;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner x=new Scanner(System.in);
int A,B;
System.out.println("AA=x.nextInt();
B= x.nextInt();
for (int i=A; i<=B; i++){
System.out.println(Math.pow(i,3));
}
}
}



  1. n(1

package com.company;


import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner x=new Scanner(System.in);
int n, S=0;
n=x.nextInt();
while(n>0) {
S=S+n%10;
n/=10;
}
System.out.println(S);
}

}


  1. n dan m gacha sonlar ichidan faqat tub sonlarning yig’indisini hisoblash dasturini tuzing?

package com.company;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner x=new Scanner(System.in);
double S=0;
System.out.print("n=");
int n=x.nextInt();
for (int i=2; i<=n; i++) {
for (int j=2; j<=i; j++){
if (i==j) {
System.out.println(i+ " ");
S=S+i;
}
if (i%j==0) {
break;
}
}
}
System.out.println(S);
}
}



  1. Yoshi yillarda aniqlovchi 40-59 gacha butun son berilgan. Son kiritilganda unga mos so'zlarda ifodalovchi dastur tuzilsn. (“qirq yosh”, “qirq uch yosh” va h.k.).

package com.company;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner kirit=new Scanner(System.in);
int n;
System.out.println("30-89 gacha butun son kiriting");
n=kirit.nextInt();
int onlar=n/10;
int birlar=n%10;
switch (onlar){
case 1: System.out.print("o`n"); break;
case 2: System.out.print("yigirma"); break;
case 3: System.out.print("o`ttiz"); break;
case 4: System.out.print("qirq"); break;
case 5: System.out.print("ellik"); break;
case 6: System.out.print("oltmish"); break;
case 7: System.out.print("yetmish"); break;
case 8: System.out.print("saskon"); break;
case 9: System.out.print("toqson"); break;
}
switch (birlar) {
case 1: System.out.print("bir"); break;
case 2: System.out.print("ikki"); break;
case 3: System.out.print("uch"); break;
case 4: System.out.print("tort"); break;
case 5: System.out.print("besh"); break;
case 6: System.out.print("olti"); break;
case 7: System.out.print("yetti"); break;
case 8: System.out.print("sakkiz"); break;
case 9: System.out.print("toqqiz"); break; default:System.out.print("busonlar ichida bunday son mavzjud emas"); } }
}


  1. N (N>0) butun son berilgan. Quyidagi yig‘indini hisoblovchi dastur tuzilsin: S=1-1/2+1/3+ . . . +(-1)N+1 1/N.

package com.company;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner x=new Scanner(System.in);
int n; double S=0;
n=x.nextInt();
for (int i=1; iS=S+Math.pow(-1,i+1)/i;
System.out.println(S);
} }
}



  1. Oyning raqami berilgan. Shu oyda nechta kun borligini aniqlovchi dastur tuzilsin.

package com.company;
import java.util.Scanner;
public class Main {

public static void main(String[] args) {


Scanner x=new Scanner(System.in);
System.out.print("Oyning raqami kiriting ");
int i= x.nextInt();
switch (i){
case 1: System.out.print(" Yavarda 31 kun bor"); break;
case 2: System.out.print(" Fevralda 28 kun bor"); break;
case 3: System.out.print(" Martda 31 kun bor"); break;
case 4: System.out.print(" Aprelda 31 kun bor"); break;
case 5: System.out.print(" Mayda 31 kun bor"); break;
case 6: System.out.print(" Iyunda 31 kun bor"); break;
case 7: System.out.print(" Iyulda 31 kun bor"); break;
case 8: System.out.print(" Avgustda 31 kun bor"); break;
case 9: System.out.print(" Sentyabrda 31 kun bor"); break;
case 10: System.out.print(" Oktaybrda 31 kun bor"); break;
case 11: System.out.print(" Noyabrda 30 kun bor"); break;
case 12: System.out.print(" Dekabrda 31 kun bor"); break; default:
System.out.println("Bunday oy mavjud emas");

}


}
}

  1. max(a,b,c)+min(a,b,c) ni aniqlash dasturini tuzing?

package com.company;

import java.util.Scanner;

public class Main {

public static void main(String[] args) {


Scanner x=new Scanner(System.in);
int a,b,c;
a=x.nextInt();
b=x.nextInt();
c=x.nextInt();
int S=Math.max(Math.max(a,b),c)+Math.min(Math.min(a,b),c);
System.out.println(S);
}
}


  1. X ( ) xaqiqiy va N (N>0) butun sonlari berilgan. Quyidagi ifoda qiymatini hisoblash dasturi tuzilsin: X- X2/2+ X3/ 3- ... +(-1)N-1 XN/ N.

import java.util.Scanner;


public class Main {
public static void main(String[] args) {
Scanner kirit = new Scanner(System.in);
double x, y; int n;
System.out.print("x=");
x = kirit.nextDouble();
System.out.print("n=");
n= kirit.nextInt();
y=0;
for(int i=1; i<=n; i++){
y=y+Math.pow(-1,i-1)*Math.pow(x,i)/i;
System.out.println("y=" + y);}

}
}




  1. . hisoblash dasturini tuzing.

package com.company;

import java.util.Scanner;

public class Main {

public static void main(String[] args) {


Scanner kirit=new Scanner(System.in);
int x; double S=0, P=1;
x=kirit.nextInt();
for (int j=1; j<10; j++){
S=Math.pow(Math.cos(j),j)+Math.pow(j,2);
System.out.println(S);
}
}
}



  1. For operatori orqali x qadam bo’yicha siklni tashkil qilishni misol yordamida tushuntirib bering.

package com.company;

import java.util.Scanner;

public class Main {

public static void main(String[] args) {


Scanner kirit=new Scanner(System.in);
int x; double S=0, P=1;
x=kirit.nextInt();
for (int j=1; j<10; j++){
S=S+Math.pow(j,2)/P*j+j;
System.out.println(S);
}
}
}



  1. A va B butun musbat sonlari berilgan(A > B). A uzunlikdagi kesmada maksimal darajada B kesma joylashtirilgan. A kesmaning bo'sh qismini aniqlovchi programma tuzilsin. Ko'paytirish va bo'lish amallarini ishlatmang.

package com.company;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner x=new Scanner(System.in);
int A,B;
A=x.nextInt();
B=x.nextInt();
while (A!=B)
if (A>B){
A=A-B;
}
else B=B-A;
System.out.println(A);
}

}



  1. A va B butun musbat sonlari berilgan(A > B). A uzunlikdagi kesmada B kesmadan nechta joylashtirish mumkinligini aniqlovchi programma tuzilsin. Ko'paytirish va bo'lish amallarini ishlatmang.

package com.company;
import java.util.Scanner;
public class Main {

public static void main(String[] args) {


Scanner x=new Scanner(System.in);
int A,B;
A=x.nextInt();
B=x.nextInt();
int k=0;
while (A>B)
A=A-B;
k=k+1;
System.out.println(A);
System.out.println(k);

}
}




  1. N natural soni berilgan (N > 1). (1 + 2 + … + K) >= N shart bajariladigan eng kichik K sonini aniqlovchi programma tuzilsin. 1 dan K gacha bo’lgan yig’indi ham ekranga chiqarilsin.

package com.company;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner x=new Scanner(System.in);
int n,i=0,S=0;
n=x.nextInt();
while ((S+i+1)<=n){
i++;
S=S+i;
}
System.out.println("k="+i);
System.out.println("S="+S);
}
}



  1. N natural soni berilgan (N > 1). (1 + 2 + 3 +… + K) <= N shart bajariladigan eng katta K sonini aniqlovchi programma tuzilsin. 1 dan K gacha bo’lgan yig’indi ham ekranga chiqarilsin.

package com.company;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner x=new Scanner(System.in);
int n,i=0,S=0;
n=x.nextInt();
while ((S+i+1)=>n){
i--;
S=S+i;
}
System.out.println("k="+i);
System.out.println("S="+S);
}
}



  1. A va B butun musbat sonlari berilgan. Berilgan sonlarning eng kata umumiy bo'luvchisini aniqlovchi dastur tuzilsin.

package com.company;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner x=new Scanner(System.in);
int A,B;
A=x.nextInt();
B=x.nextInt();
while (A!=B){
if (A>B)
A=A%B;
else
B=B%A;
if (A==0) A=B;
if (B==0) B=A;
}
System.out.println(A);
}
}



  1. N butun soni berilgan (N>1). N sonidan kata bo'lgan birinchi Fibonachchi sonini aniqlovchi dastur tuzilsin. Fibonachchi sonlari quyidagi qonuniyatlar asosida topiladi.

F1 = 1; F2 = 1; FK = FK-1 + FK-2; K = 3,4,…

  1. A va B butun soni berilgan (A




  1. 1-dastur.txt nomli fayl yarating va fayl tarkibiga matn yozish dasturini tuzing.

package com.company;
import java.io.*;
import java.util.Scanner;
public class Main {
public static void main(String[] args) throws IOException {
File file = new File( "1-dastur.txt");
FileWriter fw = new FileWriter(file);
System.out.println("Matn kiriting");
fw.write(new Scanner(System.in).nextLine());

fw.close();


}
}

  1. Nuqta bilan tugaydigan satr berilgan. Satrda nechta so‘z borligini hisoblab chiqing.

package com.company;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner x=new Scanner(System.in);
String s1=x.nextLine();
int a=1;
s1=s1.trim();
for (int i = 0; i < s1.length()-1; i++) {
if(s1.charAt(i)==' '&&s1.charAt(i+1)!=' '){
a++; }
}
System.out.println(a);
}
}



  1. Ingliz matnidan iborat satr berilgan. b harfi bilan boshlanuvchi so‘z nechtaligini toping.

package com.company;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("So'zlar sonini kiriting: ");
int n = scanner.nextInt();
int k = 0;
System.out.print(n + " ta so'z kiriting: ");
String[] sozlar = new String[n];
for (int i = 0; i < n; i++) {
sozlar[i] = scanner.next();
}
System.out.print("b xarfi bilan boshlanadigan so'zlar: ");
for (String s : sozlar) {
if (s.startsWith("b")) {
k++;
System.out.print(s + ", ");
}
}
System.out.print("\nb xarfi bilan boshlanadigan so'zlar soni: " + k + " ta");

}
}


  1. Satr berilgan. Unda r, k, t harflari qanchaligini hisoblab chiqing.

package com.company;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner kirit = new Scanner(System.in);
String s; int k=0;
System.out.print("s=");
s= kirit.next();
char x='r';
for (int i=0; iif (s.charAt(i)==x)
k++;
System.out.println("Berilgan satrda " + k + " ta " + x + " belgi bor");
int m=0; char y='t';
for (int i=0; iif (s.charAt(i)==y)
m++;
System.out.println("Berilgan satrda " + m + " ta " + y + " belgi bor");
int f=0; char z='k';
for (int i=0; iif (s.charAt(i)==z)
f++;
System.out.println("Berilgan satrda " + f + " ta " + z + " belgi bor");
}
}



  1. Satr berilgan. Unda *(yulduzcha), ;(nuqta vergul), :(ikki nuqta) belgilari qanchaligini hisoblab chiqing.

package com.company;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner kirit = new Scanner(System.in);
String s; int k=0;
System.out.print("s=");
s= kirit.next();
char x='*';
for (int i=0; iif (s.charAt(i)==x)
k++;
System.out.println("Berilgan satrda " + k + " ta " + x + " belgi bor");
int m=0; char y=';';
for (int i=0; iif (s.charAt(i)==y)
m++;
System.out.println("Berilgan satrda " + m + " ta " + y + " belgi bor");
int f=0; char z=':';
for (int i=0; iif (s.charAt(i)==z)
f++;
System.out.println("Berilgan satrda " + f + " ta " + z + " belgi bor");
}
}



  1. Matndan iborat satr berilgan. Eng qisqa va eng uzun so‘z uzunliklarini toping.




  1. Orasida ikki nuqtasi bo‘lgan belgili satr berilgan. Ungacha bo‘lgan belgilar qanchaligini aniqlang.

  2. Nuqta bilan tugaydigan, matndan tashkil topgan satr berilgan. Uchta harfdan iborat so‘zni ekranga chiqaring.


  1. Berilgan satrdagi barcha na qismiy satrni nad qismiy satr bilan almashtirng.58

package com.company;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
System.out.println("So'z kiriting ");
String s=new Scanner(System.in).nextLine();
System.out.println(s);
s= s.replaceAll("na","nad");
System.out.println(s);
}
}



  1. Satr berilgan. Unda abc qismiy satr necha marta uchrashini aniqlang.

package com.company;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
System.out.println("So'z kiriting ");
String s=new Scanner(System.in).nextLine();
System.out.println(s);
int t=0;
for (int i = 1; i < s.length()-1; i++) {

if (s.charAt(i-1)=='a' && s.charAt(i)=='b' && s.charAt(i+1)=='c')


{
t++;
}

}
System.out.println("t = " + t);


}



  1. Satr berilgan. Uning oxirgi so‘zidagi k harfi mig‘dorini hisoblab chiqing.




  1. Satr berilgan. Unda har xil belgilar necha marta uchrashini hisoblab chiqing. Ularni ekranga chiqaring.

package com.company;
public class Main {
public static void main(String[] args) {
System.out.println("symbols(Java*dasturlash#asoslari%) = " + symbols("Java*dasturlash#asoslari%"));
}
public static int symbols(String in)
{
int count=0;
for (int i = 0; i < in.length(); i++) {
if (!Character.isLetterOrDigit(in.charAt(i)) )
{
count++;
}
}
return count;
}
}



  1. Satr berilgan. Berilgan ikkita gapdagi o‘chraydigan bir xil so‘zni chop eting.




  1. Orasida bitta ochilgan qavs va bitta yopilgan qavs mavjud bo‘lgan belgili satr berilgan. Bu qavslar orasidagi barcha belgilarni ekranga chiqaring.

package com.company;
import static com.sun.org.apache.xalan.internal.xsltc.compiler.util.Type.Text;
public class Main {
public static void main(String[] args) {

System.out.println("result :" + getText("hjdffh(Maftuna(Raxmonova)fd(gfgfg)fsffsfoo"));


}
public static String getText(String str) {

return str.substring(str.indexOf('(') + 1, str.indexOf(')'));


}
}



  1. Ikki nuqta bilan tugovchi va nuqta vergul bilan ajratilgan so‘zlar to‘plami berilgan. a harfi bilan tugovchi so‘zlar qanchaligini aniqlang.

  2. Satr berilgan. Tarkibida kamida bitta k harfi bo‘lgan so‘zni ko‘rsating.

package com.company;
import java.util.Arrays;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Main {
public static void main(String[] args) {

Download 79,63 Kb.

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