Advertisements
Advertisements
प्रश्न
Observe the following code. It may contain Syntax, Logical or runtime errors. Execute it in Java and identify the error, if any. Rewrite the code without the error. Also write the aim of the code.
import java.io.*;
class Paper
}
int fnBox(int limit)
{
for(int sum = 0, t= 1; t <= limit;t++)
sum = sum + t;
return sum;
}
void main()
{
int N;
Scanner sc = new Scanner(System.in);
System.out.print("Enter limit:");
N = sc.nextInt();
System.out.print("Result=" + fnBox(N));
}
}कोड लेखन
Advertisements
उत्तर
import java.io.*;
import java.util.*;
class Paper
}
int fnBox(int limit)
{
for(int sum = 0, t= 1; t <= limit;t++)
sum = sum + t;
return sum;
}
void main()
{
int N;
Scanner sc = new Scanner(System.in);
System.out.print("Enter limit:");
N = sc.nextInt();
System.out.print("Result=" + fnBox(N));
}
}shaalaa.com
क्या इस प्रश्न या उत्तर में कोई त्रुटि है?
