Advertisement
starcat38

Задача 5

Oct 5th, 2014
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.90 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class task5 {
  4.     static int[] m={1,0,1,0,1};
  5.     static int i,j,er;
  6.     public static void main(String[] args) {
  7.         Scanner sc = new Scanner(System.in);
  8.         /*
  9.          * Здесь теоритически можно вводить массив из 0 и 1
  10.         m= new int[100];
  11.         while(sc.hasNextInt()) {
  12.             m[i]=sc.nextInt();
  13.             i++;
  14.         }
  15.         */
  16.         i=m.length-1;
  17.         if (m[0]==0){
  18.             for(j=0;j<i;j+=2){
  19.                 if (m[j]!=0) {
  20.                     er++;
  21.                     break;
  22.                 }
  23.             }
  24.             for(j=1;j<=i;j+=2){
  25.                 if (m[j]!=1) {
  26.                     er++;
  27.                     break;
  28.                 }
  29.             }
  30.         }
  31.         else {
  32.             for(j=0;j<i;j+=2) {
  33.                 if (m[j]!=1) {
  34.                     er++;
  35.                     break;
  36.                 }
  37.             }
  38.             for(j=1;j<i;j+=2){
  39.                 if (m[j]!=0) {
  40.                     er++;
  41.                     break;
  42.                 }
  43.             }
  44.         }
  45.         if (er==0) {
  46.             System.out.print("Строго чередуются");
  47.         }
  48.         else {
  49.             System.out.print("Не чередуются строго");
  50.         }
  51.     }
  52.  
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement