Мазмұнға өту
Обложка сообщества Разное

А(10) массив берілген. Ең бірінші нөлдік элементің алдындағы оң таңбалы элементтердің қосындысы мен санын табыңыз.

import java.util.Random;
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author DMyrzaka
*/
public class Esep10 {
public static void main(String args[]){
int a[] = new int[10];
int n=10;
int j=0;
int sum=0,k=0;
Random r = new Random();
for (int i=0;i<n;i++)
a[i]=r.nextInt(10);
for(int i=0;i<n;i++)
System.out.print("a["+i+"]="+a[i]+" ");
for(int i=0;i<n;i++)
if (a[i]==0) { j=i; break; }
System.out.println("j="+j);
for (int i=0;i<j;i++){
if (a[i]>0){
sum=sum+a[i];
k++;
}
}
System.out.println("\nЕн биринши нолдик элементтинин он сандардын косындысы " +sum+" жане саны "+k);
}
}
 
0
0
3076

Осы тақырып бойынша