How do I fix the negative number of the code so it will output none? 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(); //Add Loop to get odd Numbers for(int i=1;i<=a;i=i+2){ System.out.print(odds(i)+" "); } //String result = odds(a);Not Required //result = Main.odds(a); Not Required } }
How do I fix the negative number of the code so it will output none?
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();
//Add Loop to get odd Numbers
for(int i=1;i<=a;i=i+2){
System.out.print(odds(i)+" ");
}
//String result = odds(a);Not Required
//result = Main.odds(a); Not Required
}
}
Trending now
This is a popular solution!
Step by step
Solved in 3 steps