- 5
Write a program to display only even number and ignoring the odd numbers from a range given by the user.
programming in java
8 Respuestas
+ 2
Easy enough, where's the problem?
Note: A number n is even if n % 2 == 0
+ 2
please post the code which you had tried already, then we can correct your mistakes.
Do not expect the code.
+ 1
Already Robobrine has given you a hint about how to find even number.
Try to code it step by step.
1. Take the user input by using scanner, and print the user input using println
2. Use a for or while loop and Print the numbers in between that range
3. Use an IF statement and print the even numbers only
+ 1
Do u need to submit any college assignment? Don't expect the entire code here bro.. just think instead of posting "pls sir", " pls pls"
+ 1
class JavaExample
{
public static void main(String args[])
{
int n = 100; System.out.print("Even Numbers from 1 to "+n+" are: ");
for (int i = 1; i <= n; i++)
{
if (i % 2 == 0)
{
System.out.print(i + " ");
}
}
}
}
Output:
Even Numbers from 1 to 100 are: 2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 42 44 46 48 50 52 54 56 58 60 62 64 66 68 70 72 74 76 78 80 82 84 86 88 90 92 94 96 98 100
0
Yeah, as Sunil told, there's no point in keeping the entire code here because u need to develop it.. already he and robobrine have explained the algorithm in detail.. try the code bro..
0
Pls jatin.. don't waste ur time (which I don't think u r valuing) and ours.. just go into a room, lock urself in and think, think, think.. bye
0
use continue
in for loop
example:
for(i=0;i<n;i++)
{
if(a%2==o){
document.write(a)
}else
continue;
}