+ 4
Tell me please ...whats wrong with this program?
import java.util.*; class sum { public static void main(String[] args) { float x,n,s=0,i,g,h; Scanner in= new Scanner(System.in); System.out.println("enter value of x and term of the series"); x=in.nextFloat(); n=in.nextFloat(); g=math.pow(x,i); h=math.sqrt(i); for(i=1;i<=n;i++) { s=s+ g/h; } System.out.println("sum series="+s); } }
7 ответов
+ 15
//I have listed all errors , U must have followed mine comment carefully ,
//btw here is the corrected code
import java.util.*;
class sum
{
public static void main(String[] args)
{
float x,n,s=0,i=2,g,h;
Scanner in= new Scanner(System.in);
System.out.println("enter value of x and term of the series");
x=in.nextFloat();
n=in.nextFloat();
g=(float)Math.pow(x,i);
h=(float)Math.sqrt(i);
for(i=1;i<=n;i++)
{
s=s+ g/h;
}
System.out.println("sum series="+s);
}
}
+ 13
if u don't initialize i , then how the compiler will know that what power should x be raised ... and that value to be stored in variable g
+ 12
1)System.out.print
2)Math.pow
3)Math.sqrt
4)Math.pow & Math.sqrt returns a double value , so there will be loss of precision when assigned to float type , its better to use typecasting
5)In Math.pow(x,i)
//here i is not initialized
//only these errors comed to my notice 😅
+ 6
Variable i is not initialized
+ 4
we don't initialize 'i'... m talking about your 5th point
+ 3
and what's wrong...I'm not getting required output
+ 3
Thanks...the way I have written g&h ...there it's shows a error...even after intializing 'i' ... what's wrong there....