Jump to content

no 2d masīva izvada pāra skaitļus


Go to solution Solved by ju,

Recommended Posts

 Sveiki, es pašmācības ceļā mācos Java valodu un sāku apgūt divdimensiju masīvu. Mēģināju uztaisīt programmu,kas izvada pāra skaitļus no masīva, bet programma met arā visus skaitļus, varbūt kāds var pateikt, vai ieteikt, ko mainīt kodā.?

 

public class aa {

	public static void main(String[] args) {
		
		int a[][] = new int [5][5];
		int i,j;
		int par;
		
		for( i = 0; i <a.length; i++ ){
			for( j = 0; j < a[i].length; j++){
				a[i][j] = (int)(Math.random()*10);
				if (a[i][j]%2 == 0);
				par = a[i][j];
				System.out.println(par);
			}
			System.out.println();
		}

	}
}

Edited by artG
Link to post
Share on other sites
sharklasers


int a[][] = new int [5][5];

int i,j;

int par;

for( i = 0; i <a.length; i++ ){

    for( j = 0; j < a.length; j++){

        a[j] = (int)(Math.random()*10);

        if (a[j]%2 == 0 && a[j] != 0) {

            par = a[j];

            System.out.println(par);

        }

    }

    System.out.println();

}

Edited by sharklasers
Link to post
Share on other sites

 

 

if nevajag {} ?
Paldies, vajadzēja gan 

 

 

 if (a[j]%2 == 0 && a[j] != 0)
paldies, nebiju iedomājies ,ka var pielikt vēl kādu operatoru klāt 
Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...