Cov txheej txheem:

Yuav ua li cas sib pauv arrays hauv Java?
Yuav ua li cas sib pauv arrays hauv Java?

Video: Yuav ua li cas sib pauv arrays hauv Java?

Video: Yuav ua li cas sib pauv arrays hauv Java?
Video: yuav ua li cas lub neej thiaj hloov pauv kom zoo dua qub 2024, Kaum ib hlis
Anonim

Swap ob Arrays Piv txwv:

  1. pob com. onlinetutorialspoint.
  2. ntshuam java ua . siv.
  3. public class SwappingTwoArrays {
  4. public static void main(String args) {
  5. Scanner input_size = tshiab Scanner(System. in);
  6. Qhov system.
  7. int loj = input_size.
  8. int array1 = new int[size], array2 = new int[size], buffer = new int[size];

Ua raws li qhov no hauv kev txiav txim siab, koj yuav pauv li cas hauv Java?

Nyeem cov lej los ntawm cov neeg siv siv cov txheej txheem nextInt() ntawm chav Scanner.

Yuav swap lawv:

  1. Tsim qhov sib txawv (temp), pib nws nrog 0.
  2. Muab tus lej thib 1 rau temp.
  3. Muab tus lej thib 2 rau tus lej thib 1.
  4. Muab temp rau tus lej thib ob.

Tom qab ntawd, lo lus nug yog, ua li cas koj pauv ob tus lej hauv Java? Java Program

  1. import java.util.*;
  2. chav kawm Swap_With {
  3. public static void main(String args) {
  4. int x, y, t; // x thiab y yog sib pauv.
  5. Scanner sc = tshiab Scanner(System.in);
  6. System.out.println("Sau tus nqi ntawm X thiab Y");
  7. x = sc.nextInt();
  8. y = sc.nextInt();

Ib tug kuj yuav nug, ua li cas koj pauv cov khoom hauv Arraylist?

sib pauv () txoj kev swaps tus cov ntsiab lus ntawm cov haujlwm uas tau teev tseg hauv cov npe teev tseg.

1. Hloov ob lub ntsiab lus hauv arraylist – Sau. swap()

  1. list – Cov npe uas yuav hloov cov ntsiab lus.
  2. i – qhov Performance index ntawm ib lub caij yuav tsum tau swapped.
  3. j – qhov Performance index ntawm lwm yam yuav tsum tau swapped.

Yuav ua li cas koj swap ob tus lej hauv ib qho array hauv Java?

Swap ob Arrays Piv txwv:

  1. pob com. onlinetutorialspoint.
  2. import java. siv.
  3. public class SwappingTwoArrays {
  4. public static void main(String args) {
  5. Scanner input_size = tshiab Scanner(System. in);
  6. Qhov system.
  7. int loj = input_size.
  8. int array1 = new int[size], array2 = new int[size], buffer = new int[size];

Pom zoo: