How do I make my code print out possitive odd numbers? example: Input: 5 Output: 1,3,5 Input: 8 Output: 1,3,5,7 import java.lang.Math; import java.util.Scanner; public class MidtermProblems { public static String odds(int a) { int odds; odds = a; String s; if(odds > 0) { //s = odds; return "" + odds; } else if(odds < 0) { s = "None"; } else { s = ""; } return s; } public static void main(String[] args) { Scanner in = new Scanner(System.in); int a=0; System.out.println("Enter a: "); a = in.nextInt(); String result = odds(a); result = MidtermProblems.odds(a); } }
How do I make my code print out possitive odd numbers?
example:
Input: 5
Output: 1,3,5
Input: 8
Output: 1,3,5,7
import java.lang.Math;
import java.util.Scanner;
public class MidtermProblems
{
public static String odds(int a)
{
int odds;
odds = a;
String s;
if(odds > 0)
{
//s = odds;
return "" + odds;
}
else if(odds < 0)
{
s = "None";
}
else
{
s = "";
}
return s;
}
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int a=0;
System.out.println("Enter a: ");
a = in.nextInt();
String result = odds(a);
result = MidtermProblems.odds(a);
}
}
Trending now
This is a popular solution!
Step by step
Solved in 2 steps