About Question enthuware.ocajp.i.v7.2.1242 :

Help and support on OCA OCP Java Programmer Certification Questions
1Z0-808, 1Z0-809, 1Z0-815, 1Z0-816, 1Z0-817

Moderator: admin

Post Reply
Michailangelo

About Question enthuware.ocajp.i.v7.2.1242 :

Post by Michailangelo »

I don't see the args[2] reference in the code.

admin
Site Admin
Posts: 10114
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.ocajp.i.v7.2.1242 :

Post by admin »

Code: Select all

int i = Integer.parseInt(args[1]);   
System.out.println(args[i]);
args[1] is 2
so i is 2
therefore, args is args[2]

HTH,
Paul.
If you like our products and services, please help us by posting your review here.

Michailangelo

Re: About Question enthuware.ocajp.i.v7.2.1242 :

Post by Michailangelo »

I should pay more attention :oops: .

satar
Posts: 10
Joined: Tue Feb 12, 2013 9:12 pm
Contact:

Re: About Question enthuware.ocajp.i.v7.2.1242 :

Post by satar »

Yeah, this one got me also

deepa.patre
Posts: 15
Joined: Thu Dec 13, 2012 9:44 am
Contact:

Re: About Question enthuware.ocajp.i.v7.2.1242 :

Post by deepa.patre »

I have a basic question,
why is the method name just parseInt() instead of parseInteger()?

Please reply,

admin
Site Admin
Posts: 10114
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.ocajp.i.v7.2.1242 :

Post by admin »

You have to ask Java designers that :)
If you like our products and services, please help us by posting your review here.

peckw1
Posts: 1
Joined: Mon Mar 30, 2015 3:00 pm
Contact:

Re: About Question enthuware.ocajp.i.v7.2.1242 :

Post by peckw1 »

If I run the code with 4 and 5 I also get the exception, in this case shouldn't args[0] = 4 and args[1]=5?

admin
Site Admin
Posts: 10114
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.ocajp.i.v7.2.1242 :

Post by admin »

peckw1 wrote:If I run the code with 4 and 5 I also get the exception, in this case shouldn't args[0] = 4 and args[1]=5?
Yes, args[0] = 4 and args[1]=5. But I am not really sure what is your point.
Paul.
If you like our products and services, please help us by posting your review here.

maltine
Posts: 2
Joined: Wed Jul 08, 2020 8:12 am
Contact:

Re: About Question enthuware.ocajp.i.v7.2.1242 :

Post by maltine »

System.out.println(i);//2
System.out.println(args); //i=2, so, args[2] --> throw an exception
Yes, this one got me also.... :cheers:

Post Reply

Who is online

Users browsing this forum: No registered users and 14 guests