Java help

SHEN746

Member
Mar 14, 2007
12
0
0
In the 1st place your for loop structure was wrong so it won't compile. you can use for(i=1 ;i<=10 ; ) but not for(i=1;i<=10) . Unless ur using the enhanced for loop which is there from java 1.5 onwards but that also uses a colon ( : ) not a semi-colon. And y r u proceeding to print i without incrementing it ?!. Which will only print the same value again and again rt ?!.Regarding your case it seems u simply want to have a summtion of squares from 1 to 10 right ?!. which mens (1^2)+(2^2)+(3^2)+....rt ?!(i.e : 1+4+9+16+25+..etc rt?). ^ stand for square root in java. In that case in could be done like the following :
class s
{

public static void main(String args[])
{
int tot =0;
int square=0;
for (int i=1; i<=10; )
{
square=(i*i);
System.out.println("The Current Square Root Calculated is : "+square);
i+=1;

tot+= square;

}
System.out.println("End of Loop Total Value of Summation is : "+tot);
}
}

If this is not what u want or if ur not clear about anything pls let me know I'll be more than happy to help out :-) !!.
 

ram4mira

Active member
  • Jan 14, 2007
    2,628
    17
    38
    36
    chanaka89 said:
    Machan SCJP karanna kalin karana podi cource1k
    C,C++ vage karala nethi unta java tikak avulne mulinma e nisa eka karala thama SCJP karanna yanne.


    appata hudu man meloo magulak danne na...eth dan ara SCJP ekata thama course eka karanne...mata kela weida manda
     

    chanaka89

    Well-known member
  • Sep 27, 2007
    7,286
    53
    48
    36
    Kandy / Kurunegala
    ram4mira said:
    appata hudu man meloo magulak danne na...eth dan ara SCJP ekata thama course eka karanne...mata kela weida manda
    Uba C ehema karala tienavada kalin?:nerd: mata nan davas 3n kela vela inne man kalin mukuthma karala ne:oo: studiesui javai jam vela inne:confused:
     

    SHEN746

    Member
    Mar 14, 2007
    12
    0
    0
    Mona pachada Java is much more easier than c,c++ !!. you can have java as your 1st language and not worry about it at all !!. Just keep doing what ur doing !!.
     

    siri24

    Well-known member
  • Dec 13, 2007
    4,258
    311
    83
    ලංකා
    chanaka89 said:
    machan meka compile ven nene:(
    machan
    for(int i=0 ; i<=10 i++){
    int s=i*i;
    System.out.println(s);
    }
    full code eka balapan..
    class s
    {
    public static void main(String args[])
    {
    for(int i=0 ; i<=10 i++)
    {
    int s=i*i;
    System.out.println(s);
    }
    }
    }

    me red tika witarai type karanna one.. uba uda ewath type kartada??
     

    ram4mira

    Active member
  • Jan 14, 2007
    2,628
    17
    38
    36
    chanaka89 said:
    Uba C ehema karala tienavada kalin?:nerd: mata nan davas 3n kela vela inne man kalin mukuthma karala ne:oo: studiesui javai jam vela inne:confused:


    mona C da ban...Com language ekak kiyanne mkakda kiyala danneth course ekata gyata passe...:P :P
     

    SHEN746

    Member
    Mar 14, 2007
    12
    0
    0
    Doing Java as ur 1st computer language is a good thing !!. these days ppl are moving ahead of java to languages like python !!. And not behind java to languages like c++ !!.
     

    chanaka89

    Well-known member
  • Sep 27, 2007
    7,286
    53
    48
    36
    Kandy / Kurunegala
    siri24 said:
    machan
    for(int i=0 ; i<=10 i++){
    int s=i*i;
    System.out.println(s);
    }
    full code eka balapan..
    class s
    {
    public static void main(String args[])
    {
    for(int i=0 ; i<=10 i++)
    {
    int s=i*i;
    System.out.println(s);
    }
    }
    }

    me red tika witarai type karanna one.. uba uda ewath type kartada??
    hari a tika vtharai type kale
    errorny5.jpg
     

    SHEN746

    Member
    Mar 14, 2007
    12
    0
    0
    Copy & paste the code I've given in blue it works & explains itself as well !!.



    class s
    {

    public static void main(String args[])
    {
    int tot =0;
    int square=0;
    for (int i=1; i<=10; )
    {
    square=(i*i);
    System.out.println("The Current Square Root Calculated is : "+square);
    i+=1;

    tot+= square;

    }
    System.out.println("End of Loop Total Value of Summation is : "+tot);
    }
    }
     

    SHEN746

    Member
    Mar 14, 2007
    12
    0
    0
    chanaka89 said:
    hari a tika vtharai type kale
    errorny5.jpg


    Copy & paste the code I've given in blue it works & explains itself as well !!.



    class s
    {

    public static void main(String args[])
    {
    int tot =0;
    int square=0;
    for (int i=1; i<=10; )
    {
    square=(i*i);
    System.out.println("The Current Square Root Calculated is : "+square);
    i+=1;

    tot+= square;

    }
    System.out.println("End of Loop Total Value of Summation is : "+tot);
    }
    }
     

    chanaka89

    Well-known member
  • Sep 27, 2007
    7,286
    53
    48
    36
    Kandy / Kurunegala
    SHEN746 said:
    Copy & paste the code I've given in blue it works & explains itself as well !!.



    class s
    {

    public static void main(String args[])
    {
    int tot =0;
    int square=0;
    for (int i=1; i<=10; )
    {
    square=(i*i);
    System.out.println("The Current Square Root Calculated is : "+square);
    i+=1;

    tot+= square;

    }
    System.out.println("End of Loop Total Value of Summation is : "+tot);
    }
    }
    thanks dude:D have to study more about this