lif,universe....

// c code
#include<stdio.h>

void main()
{
int a;
while(1)
{

scanf("%d",&a);

if(a==42)

break;
else 

printf("%d",a);
}
 
} 




//java code

import java.util.*;
 
class prog1
{
Scanner var=new Scanner(System.in);
int a;
while(1)
{
 a=var.nextInt();

 if(a==42)

 break;

 else

 System.out.println(a);
 
}
 
}

sorry…for line spacing…c code shows compile time error and java code shows runtime error…thanks in advance

I went through ur profile and it says that C is getting an RE…and the reason being ur code isnt returning 0 to indicate successful completion…hence the RE NZEC(non zero exit code)…so make the return type of main as int and add a return 0 statement at the end…!!!

and as far as ur java code is concerned…it is getting a compile time error cause u are using while(1)…in c/c++ it is valid…but in java u cannot use integral values…u can only use boolean values there…so change it to while(true)…hope this helps…:slight_smile:

1 Like

using int in place of void and using namespace std worked for me
thanks