Advertisement
realever15

俊豪作業簡單03

Mar 11th, 2015
205
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.84 KB | None | 0 0
  1. package fg;
  2.  
  3. import java.util.Scanner;
  4. public class fg {
  5.  
  6.  
  7.     public static void main(String[] args) {
  8.     Scanner scn = new Scanner(System.in);
  9.     int[] f1 = new int[10];
  10.     int[] f2 = new int[10];
  11.     System.out.print("輸入父代1染色體的內容:");
  12.     for(int i=0;i<10;i++)
  13.     {
  14.         f1[i]=scn.nextInt();
  15.        
  16.     }
  17.     System.out.print("輸入父代2染色體的內容:");
  18.     for(int i=0;i<10;i++)
  19.     {
  20.         f2[i]=scn.nextInt();
  21.     }
  22.     int temp;
  23.     for(int i=1;i<11;i+=2)
  24.     {
  25.         temp=f1[i];
  26.         f1[i]=f2[i];
  27.         f2[i]=temp;
  28.     }
  29.     System.out.print("子代1的染色體內容:");
  30.     for(int i=0;i<10;i++)
  31.     {
  32.         System.out.print(f1[i]+" ");
  33.     }
  34.     System.out.printf("\n子代2的染色體內容:");
  35.     for(int i=0;i<10;i++)
  36.     {
  37.         System.out.print(f2[i]+" ");
  38.     }
  39.    
  40.  
  41.     }
  42.  
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement