Life, the Universe, and Everything :java Wrong Answer coming

Please check what is the mistake in this . I am getting wrong answer for this.

Thanks

class LifeUniverse{

public static void main(String[] args){

    String input="";
    for(int i=0; i<args.length;i++){

       input=args[i];
        if(input=="42")
            return;
        System.out.println(input);

    }

}}

You are not taking any input in your solution. Input on codechef is not by command line parameters but by using the standard input. So for standard input in java you should use BufferedReader or Scanner(though Scanner is very slow).

2 Likes

i have used scanner and have taken input from user my code is working fine on my pc but here its giving wrong answer y is it so?
import java.util.Scanner;
class Bruteforce{

public static void main(String[] args) {
    // TODO code application logic here
   
   Scanner sc=new Scanner(System.in);
   int[] a=new int[5];
   //System.out.println("enter elements");
    for(int i=0;i<a.length;i++){
    a[i]=sc.nextInt();
    }
    for(int i=0;i<a.length;i++)
    {
        if(a[i]==42)
        break;
    System.out.println(a[i]);
    
    }

}
}

input is not command line…it is using stdin…use Scanner or BufferedReader!!!

…and also do not use == for Object comparison !