Студопедия
Случайная страница | ТОМ-1 | ТОМ-2 | ТОМ-3
АрхитектураБиологияГеографияДругоеИностранные языки
ИнформатикаИсторияКультураЛитератураМатематика
МедицинаМеханикаОбразованиеОхрана трудаПедагогика
ПолитикаПравоПрограммированиеПсихологияРелигия
СоциологияСпортСтроительствоФизикаФилософия
ФинансыХимияЭкологияЭкономикаЭлектроника

Given a positive integer n, the real numbers a1, ., an. Determine the number of pairs of consecutive integer numbers in this sequence which have different signs.

Читайте также:
  1. A Decide which of these statements are true (T) or false (F).
  2. A different approach to the job
  3. A peninsula is a piece of land, which is almost completely surrounded by water, but is joined to a larger mass of land.
  4. A strait is a narrow passage of water between two areas of land, which is connecting two seas.
  5. A Teacher’s Lot Is Certainly a Different One
  6. A The following are dictionary definitions of different types of markets.
  7. A) Pronunciation drill. Pronounce the words, then look at the given map and fill in the table below.

Given a positive integer n, the integers a1,..., an. Find the number and the sum of the members of the sequence that are divisible by 5 and not divisible by 7.

import java.util.Scanner;

import java.util.*;

import java.io.*;

public class Zd1 {

public static void main(String[] args) {

Scanner in = new Scanner(System.in);

int n;

int kolp=0;

int i=0;

int[] c;

int sum=0;

System.out.println("введите размерность n");

n = in.nextInt();

c = new int[n];

for(i = 0; i < n; i++) c[i] = in.nextInt();

for(i=0;i<n;i++){

if(c[i]%5==0 && c[i]%7!=0){

kolp=kolp+1; sum=sum+c[i];}}

System.out.println("кол-во =" +kolp);

System.out.println("сумма эл-тов ="+sum);}}

 

2 ) Given positive integers n, p, integers a1,..., an. Find product of elements of the sequence a1,..., an which are multiple of p.

import java.util.Scanner;

public class Zd1 {

public static void main(String[] args) {

Scanner in = new Scanner(System.in);

int p=0;

int n;

int[] c;

System.out.println("введите размерность последовательности");

n = in.nextInt();

System.out.println("введите число p");

p = in.nextInt();

c = new int[n];

int pp=1;

int i;

for(i = 0; i < n; i++) c[i] = in.nextInt();

for(i=0;i<n;i++)

if(c[i]%p==0)

pp=pp*c[i];

System.out.println(pp);}}

 

3) Given a positive integer n, the real numbers a1,.., an. Find: min (a2, a4,....) + max (a1, a3, a5,...).

import java.util.Scanner;

public class Zd1 {

public static void main(String[] args) {

Scanner in = new Scanner(System.in);

int p=0;

int n;

int[] c;

System.out.println("введите размерность последовательности");

n = in.nextInt();

c = new int[n];

int i;

for(i = 0; i < n; i++) c[i] = in.nextInt();

i=0;

int minc=c[0]; int maxc=c[0];

for(i=0;i<n;)

{ if(c[i]%2==0){

if(c[i]<minc)

minc=c[i];}

else { if(c[i]>maxc)

maxc=c[i];}i++;}

int sum=(minc+maxc);

System.out.println(sum);}}

 

4) Given a positive integer n, the real numbers a1,.., an. Find: max (a2, a4,....) + min (a1, a3, a5,...).

import java.util.Scanner;

public class Zd1 {

public static void main(String[] args) {

Scanner in = new Scanner(System.in);

int p=0; int n; int[] c;

System.out.println("введите размерность последовательности");

n = in.nextInt(); c = new int[n]; int i;

for(i = 0; i < n; i++) c[i] = in.nextInt();

i=0;

int minc=c[0]; int maxc=c[0];

for(i=0;i<n;)

{ if(c[i]%2==0){

if(c[i]>maxc)

maxc=c[i];}

else {

if(c[i]<minc) minc=c[i];}

i++;}int sum=(minc+maxc); System.out.println(sum);}}

Given a positive integer n, the real numbers a1,..., an. Determine the number of pairs of consecutive integer numbers in this sequence which have both positive sign.

import java.util.Scanner;

public class Zd1 {

public static void main(String[] args) {

Scanner in = new Scanner(System.in);

int p=0;

int n;

int[] c;

System.out.println("введите размерность последовательности");

n = in.nextInt();

c = new int[n];

int i;

for(i = 0; i < n; i++) c[i] = in.nextInt();

i=0;

for(i=0;i<n-1;i++){

if (c[i]>0 && c[i+1]>0){

p=p+1;}}

System.out.println(p);}}

 

Given a positive integer n, the real numbers a1,..., an. Determine the number of pairs of consecutive integer numbers in this sequence which have different signs.

import java.util.Scanner;

public class Zd1 {

public static void main(String[] args) {

Scanner in = new Scanner(System.in);

int p=0;

int n;

int[] c;

System.out.println("введите размерность последовательности");

n = in.nextInt();

c = new int[n];

int i;

for(i = 0; i < n; i++) c[i] = in.nextInt();

i=0;

for(i=0;i<n-1;i++){

if (c[i]>0 && c[i+1]<0 || c[i]<0 && c[i+1]>0){

p=p+1;}}

System.out.println(p);}}

 

Given a positive integer n. Throw out digits 0 and 5 from decimal representation of this number, leaving the previous order of the remaining digits. For example, out of the number 59015509 we should get 919.

import java.util.Scanner;

import java.util.*;

import java.io.*;

import java.lang.String;

public class Zd1 {

public static void main(String[] args) {

Scanner in = new Scanner(System.in);

int n;

System.out.println("введите n");

n = in.nextInt();

String nn=Integer.toString(n);

int z=0;

String b=Character.toString('0');

String c=Character.toString('5');

String ss=" ";

z=nn.length();

for(int i=0;i<z;i++){

String cc=Character.toString(nn.charAt(i));

String bb=Character.toString(nn.charAt(i));

if(cc.equals(c) || bb.equals(b));

else{

ss=ss+Character.toString(nn.charAt(i));}}

System.out.println(ss.trim());}}

 

8) Given integers a, n, x1,..., xn (n> 0). Determine number of elements in the sequence x1,..., xn which are equal to a. If such a member is not present, then the answer should be 0.

import java.util.Scanner;

import java.util.*;

import java.io.*;

public class Zd1 {

public static void main(String[] args) {

Scanner in = new Scanner(System.in);

int n; int ii=-1; int i=0; int[] c;

System.out.println("введите a");

int a=in.nextInt();

System.out.println("введите размерность n");

n = in.nextInt(); c = new int[n];

for(i = 0; i < n; i++) c[i] = in.nextInt();

for(i=0;i<n;i++){

if(c[i]==a){ ii=i+1; i=n;}}

if(ii==-1) System.out.println("0"); if (ii>=0) System.out.println(ii);}}

9) Given a positive integer n, the real numbers a1,..., an. Print "YES", if the number of positive elements in the sequence is greater than the number of negative elements, otherwise display "NO".

import java.util.Scanner;

import java.util.*;

import java.io.*;

public class Zd1 {

public static void main(String[] args) {

Scanner in = new Scanner(System.in);

int n;

int kolp=0,kolm=0;

int i=0;

int[] c;

System.out.println("введите размерность n");

n = in.nextInt();

c = new int[n];

for(i = 0; i < n; i++) c[i] = in.nextInt();

for(i=0;i<n;i++){

if(c[i]>0)

kolp=kolp+1;

if(c[i]<0)

kolm=kolm+1;}

if(kolp>kolm)

System.out.println("YES");

else

System.out.println("NO");}}

 


Дата добавления: 2015-11-16; просмотров: 69 | Нарушение авторских прав


<== предыдущая страница | следующая страница ==>
Problems of phonostylistics| Given a positive integer n, the integers a1, ..., an. Find the number and the sum of the members of the sequence that are divisible by 3 and not divisible by 5.

mybiblioteka.su - 2015-2024 год. (0.012 сек.)