About if(true) { } [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 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.

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

Im not sure why this code is not working properly as it's supossed [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 1 year ago.
Improve this question
public String createHash()
{
String[] ALPHABET={"0","1","2","3","4","5","6","7","8","9","a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z","A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"};
String[] hash={"0","1","2","3","4","5","6","7"};
for(int var=0; var==61; var++)
{
hash[7]=ALPHABET[var];
System.out.print(hash[7]);
}
return "Success";
}
I'm not quiet sure how to explain what this code is supossed to do but I hope you get what I wanted it to do. It's supposed to take the value behinde index 7 of hash and replace it with the value behinde index "var" of ALPHABET.
So at the end it should print in the cosole something like this: "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
I'm not sure where the error is. It's probabbly something extremly basic but I'm quiet new to programming...
You're seeing "Success", aren't you? This may be because of the abort-variable. var is never 61 because this condition will be checked before your for-block is executed.
It will has to be
for(int var = 0; var <= 61; var++)
if you want 62 executions of your for loop.
Anyway, I don't understand the purpose.

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.

can someone expalin me the java program? [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 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)

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());
}

Categories