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);
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.