Help! I am extremely new to
Java & am having trouble with my code. I am required to use "for" to print out odd numbers between ANY two numbers (whether even or odd) that are input by the user (the numbers are inclusive). There also has to be three columns that print out the numbers, but I'm having a hard time understanding how to create columns. Here is my code so far:
public class Hw3_2
{
public static void main (
String[] args)
{
Scanner input = new Scanner (System.in);
int firstnum;
int secondnum;
int count;
System.out.print ("Enter first integer: ");
firstnum = input.nextInt();
System.out.print ("Enter second integer: ");
secondnum = input.nextInt();
// Figure out if the firstnum is odd or even using an if statement
{
if (firstnum % 2 == 0)
{
for (count = firstnum; count <= secondnum ; count += 1 , count += 2); // I'm not sure of the best way to handle an even integer
{
System.out.println ( count += 2);
}
}
else
{
for (count = firstnum; count <= secondnum; count += 2); // If firstnum is an odd number
{
System.out.println (count += 2);
}
}
System.out.println ("List of odd numbers from " + firstnum + " to " + secondnum + "is " + count); // this is where I have issues with creating the columns
}
}
}