Well, here's my problem. I have to Count from Num1 to Num2 by input from the user. So when I input let say 1 to 5, it will display 1 3 5. If I do 2 to 6, it would display 3 and 5.
I can't seem to get the evens part. When I input 2 and 10, it inputs at the last number 11, which is exceeding. I also have to sum up all the evens together from num1 to num2. If I input 2 and then 2, it will output a 3, which is suppose to be a 0.
Here is my code. It's Line 25 to 53 i'm working on. The rest is finished right.
import java.util.*;
public class MiscLoops {
public static void main(String [] args) {
Scanner console = new Scanner(System.in);
int num1;
int num2;
int number1 = 0;
int odds = 0;
int counter = 0;
int evens = 0;
int sum = 0;
int sumOdd = 0;
int i;
int squareOdds = 0;
int count = 1;
System.out.println("first number must be less than second?");
num1 = console.nextInt();
num2 = console.nextInt();
System.out.println("odd numbers:");
while(num1 <= num2){
if (num1 % 2 ==0 )
{
evens = num1+1;
num1 +=2;
System.out.println(evens);
}
else if(num1 % 2 !=0){
odds = num1;
num1 +=2;
System.out.println(odds);
}
}
for(num1 = 0; num1 < num2; num1++){
if(evens % 2 == 0)
sum = sum + num1;
else if(number1 % 2 !=0)
sum +=number1;
}
System.out.println("sum of evens: "+ sum);
System.out.println("squares of 1 to 10");
for(i = 1; i <=10; i++){
sum = (i*i);
System.out.println(i + " " +sum);
}
for(num1 = 0; num1 <= num2; num1++){
if (num1 % 2 != 0)
squareOdds += num1*num1;
}
System.out.println("Sum of odds squared: " + squareOdds);
char upper;
System.out.printf("A to Z:\n");
for (upper = 'A'; upper <= 'Z'; upper++ ){
System.out.printf("%s",upper);
}
}
}
Any point in direction appreciated.