Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

for loop with else

$
0
0
can you please help. i think i am using else wrongly. i am trying to setup a when a user type in a number it printer out even number within range. but if they hit type more than say 40 i want it to print out "number out of range,


import java.util.Scanner;

public class ModulusCalculation
{

public static void main(String[] args)
{

System.out.println("ENTER RANGE OF EVEN NUMBERS TO FIND ");
Scanner scan = new Scanner(System.in);

for (int startingPoint = scan.nextInt(); startingPoint <= 40; startingPoint++)

{
if (startingPoint % 2 == 0)
{

System.out.println(+startingPoint);
else
System.out.println("THIS IS OUT OF RANGE");

}
}
}

}

Viewing all articles
Browse latest Browse all 51036

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>