Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package fg;
- import java.util.Scanner;
- public class fg {
- public static void main(String[] args) {
- Scanner scn = new Scanner(System.in);
- int[] f1 = new int[10];
- int[] f2 = new int[10];
- System.out.print("輸入父代1染色體的內容:");
- for(int i=0;i<10;i++)
- {
- f1[i]=scn.nextInt();
- }
- System.out.print("輸入父代2染色體的內容:");
- for(int i=0;i<10;i++)
- {
- f2[i]=scn.nextInt();
- }
- int temp;
- for(int i=1;i<11;i+=2)
- {
- temp=f1[i];
- f1[i]=f2[i];
- f2[i]=temp;
- }
- System.out.print("子代1的染色體內容:");
- for(int i=0;i<10;i++)
- {
- System.out.print(f1[i]+" ");
- }
- System.out.printf("\n子代2的染色體內容:");
- for(int i=0;i<10;i++)
- {
- System.out.print(f2[i]+" ");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement