can someone expalin me the java program? [closed] - java

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
what is the output and explain in detail, as I am very confused in args.length.
class check
{
public static void main(String args[])
{
System.out.println(args[args.length-2]);
}
}

It prints this:
java check a b c
> b
for single variable (java check a) it prints error:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: -1
at check.main(check.java:6)

Related

How can i find which method use a for loop in the java class [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 4 days ago.
Improve this question
Does java offer a simple way to do this?
I know how to find get class name of any java file(using javaParser)
But how could I be able to find which method use a for loop and find the parameters of the for loop.
Anyone guide me in the right direction? Thanks in advance.
public void show(List<String> strList){
for(String str : strList){
System.out.println(str);
}
}
how could I find this for loop and the strList as the parameter.Thx

Return method return several times [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 years ago.
Improve this question
I want to make a method return that return several times a String from a list of String. any idea ??
How about something like this:
String getRandomString(List<String> list) {
return list.get(new Random().nextInt(list.size()));
}
This isn't the most efficient way, but should do the job.

About if(true) { } [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I'm not sure if I should ask about it ,but it just makes me curious (*I found it on my colleague's codes , but not exactly same ):
Under what circumtance that "true" bellow is accepted ? * Why this line is considered as useless that's what i'm asking for explanation as I don't understand !! I meant it means same like if (true==true) , but why if( ) always true for default circumtance?
public class UnknownChecking {
public static void main(String[] args) {
if(true){
System.out.println("something");
}
}
}
* It will print "something" .
true is always true. That is called tautology.
It's the same as writing System.out.println("something"); without the if statement.

Its not coming out of the loop [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
Hi in the below code mandatoryCount = 0 and it should be increased when an image is selected but its found to be always 1 and i cant exit the loop can any one help me. Here if mandatoryCount = 0 or mandatoryCount>=imageTypeMandatory.length. It must come out of loop. But this code is working if i comment the mandatory count ==0. I cannot find the exact error.
if (dataOne.getCount() >= 1) {
mandatoryCount=0;
dataOne.moveToFirst();
while(!dataOne.isAfterLast()){
for(int iCopy=0;iCopy<imageTypeMandatory.length;iCopy++){ if(imageTypeMandatory[iCopy].trim().equalsIgnoreCase(dataOne.getString(0).trim())){
mandatoryCount++; imageTypeMandatoryCopy[iCopy]="";
}}
dataOne.moveToNext();
}
The logic is testing the moveFirst/moveNext.
if (dataOne.moveToFirst()) {
do {
for(int iCopy=0;iCopy<imageTypeMandatory.length;iCopy++){
if(imageTypeMandatory[iCopy].trim().equalsIgnoreCase(dataOne.getString(0).trim())){
mandatoryCount++;
imageTypeMandatoryCopy[iCopy]="";
}
}
} while(dataOne.moveToNext());
}

Why this declaration line does not give any error [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
int [ ] a;
What is happening in this line can anybody describe. It has spaces between [].
You are defining a reference to an array which is presently null, and therefore of undefined size.
This is correct syntax. The spaces in between square brackets are not relevant.
Here is some proper further usage:
int [] a = new int[10];

Categories