First, launch NetBeans and close any previous projects that may be open (at the
ID: 3591489 • Letter: F
Question
First, launch NetBeans and close any previous projects that may be open (at the top menu go to File ==> Close All Projects).
Then create a new Java application called "EvenThough" (without the quotation marks) that uses a while loop to check the integers 1 through 20 and prints only those integers that are even.
Use division to determine an even integer (i.e., when divided by 2 the result yields no remainder).
All output should appear on a single line, but separate each even integer with a comma and a space. Be sure the integer 20 (which is the last expected number you'll output) omits the trailing comma and space.
**Note: include commenting in your code**
Explanation / Answer
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package eventhough;
/**
*
* @author VISHAL
*/
public class EvenThough {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
int i=1; //initializing variable i with 1
System.out.println("Even Numbers are : ");
while(i<=20)
{
if(i%2==0) //if remainder will be zero,then number will be even only
{
System.out.print(i); //printing even number
if(i!=20)
{
System.out.print(", "); //printing requirements
}
}
i++; //incrementing variable i
}
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.