import java.util.Scanner;
public class While
{
public static void main(String args[]){
Scanner in = new Scanner(System.in);
System.out.print("Choose a number to find various things for: ");
int n = in.nextInt();
// Extraneous variables to keep myself organized.
int i = 0;
int b = 1;
int t = 0;
int sum1 = 0;
int sum2 = 0;
double sum3 = 0;
double total = 0;
// Extraneous code to keep simple.
System.out.println("Squares up until your number");
while ( (i * i) < n ){
System.out.println(i * i);
sum1 = sum1 + (i * i);
i++;
}
System.out.println("Now positives divisible by 10");
while ( (b * 10) < n){
System.out.println(b * 10);
sum2 = sum2 + (b * 10);
b++;
}
System.out.println("Now squares of 2!");
while ( Math.pow(2,t) < n ){
System.out.println(Math.pow(2,t));
sum3 = sum3 + (Math.pow(2,t));
t++;
}
// Second part of assignment.
total = total + (sum1 + sum2 + sum3);
System.out.println("The sum of all numbers: " + total);
System.out.println();
}
}
Now, the total needs to be separated into its own numbers. If the user puts in the number 50, the program's total will be 303. How can I get that 303 to be, 3, 0, 3, then add only the odd numbers then use a simple System.out. to print a 6 for this example?