Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

100% life saver!!! how to get sum of evennumber... =============================

ID: 3611528 • Letter: 1

Question

100% life saver!!! how to get sum of evennumber...

========================================


public class ex1
{
public static void main(String[] args)
{
  
   int i,j,k,tot;
  
  
  
for(k = 0; k < 10; k++)
if (k % 2 == 0 )
{
   System.out.println("k value is " + k);
      
  
}


  
  
}
}
100% life saver!!! how to get sum of evennumber...

========================================


public class ex1
{
public static void main(String[] args)
{
  
   int i,j,k,tot;
  
  
  
for(k = 0; k < 10; k++)
if (k % 2 == 0 )
{
   System.out.println("k value is " + k);
      
  
}


  
  
}
}

Explanation / Answer

//I am not sure what you want to do, you want the user toinput a number first? What is the whole direction here?
public class ex1
{
public static void main(String[] args)
{
  
   int i,j,k,tot;
  
  
   tot=0;
for(k = 0; k < 10; k++)
if (k % 2 == 0 )
{
   System.out.println("k value is " + k);
   tot+=k;
  
}
System.out.println("The sum of eveninteger value is: "+tot);

   
   
}
}