View Answers

July 23, 2009 at 3:17 PM

Hi Friend,

Try the following code:

class EvenNumbers{

public static void main (String args[]){

String evenNo = "";

int counter = 0;

System.out.println("Even Numbers are:" );

for (int i = 1; i <=20; i++){

if (i % 2 == 0) {

evenNo += i + " ";

counter++;

if (counter == 5) {

evenNo += "\n";

counter = 0;

}

}

}

System.out.println(evenNo);

}

}

Thanks

Try the following code:

class EvenNumbers{

public static void main (String args[]){

String evenNo = "";

int counter = 0;

System.out.println("Even Numbers are:" );

for (int i = 1; i <=20; i++){

if (i % 2 == 0) {

evenNo += i + " ";

counter++;

if (counter == 5) {

evenNo += "\n";

counter = 0;

}

}

}

System.out.println(evenNo);

}

}

Thanks

Related Tutorials/Questions & Answers:

Listing all even numbers between two numbers Hi, How to write code to list all the even numbers between two given numbers? Thanks Hi, You function will take 2 numbers and the find the even numbers between

EVEN NUMBERS i want program of even numbers?i want source code plz reply? Hi Friend, Try the following code: class EvenNumbers... counter = 0; System.out.println("Even Numbers are:" ); for (int i

Advertisements

print the even numbers between the range 100-200 Q ?write an application that print out the even numbers between the range 100-200 ? 1- which aer... prints out the even numbers between the range of 100 and 200 and then determine

How to list even numbers between 1 and 100? Hi, I Java to check if a number is even? How to list even numbers between 1 and 100? Thanks Hi, If number is divisible by 2 then its even number. Suppose you have

Java write even numbers to file In this section, you will learn how to write the even numbers to file. By using the PrintWriter class, you can write any type... have used print() method to store the even numbers to the file.ADS_TO_REPLACE_1

Write a program to list all even numbers between two numbers Java Even Numbers - Even... all the even numbers between two numbers. For this first create a class named

write an application that print out the even numbers between the range 100-200 write an application that print out the even numbers between... and determine the even numbers between them. class EvenNumbers { public static

Calculate sum of even and odd numbers In this section, you will learn how to read the file that contains even and odd numbers and calculate their sum separately. To do this, first of all, we have found all the even and odd numbers from 1

Check whether highest number is even or odd In this section, you will learn how to check highest number between the two numbers and then determine whether it is odd or even. For this, we have taken two integer variables num1 and num2

odd and even how can i make a program of even and odd using case...); System.out.println("Enter Numbers: "); int arr[]=new int[10...{ System.out.println(); System.out.println("1 Display Even

is used for inputting number. Even numbers are those numbers, which are divisible...Check even or odd number. How to check given number is even or odd? Simple if it is devided by 2 it is even and if not if is Odd

"); } } } Description : Number which is divisible by 2 is called even numbers...Even and odd functions in java Even and odd functions in java ...); int number; System.out.println("Input any number to check even

automorphic numbers how to find automorphic number in java Hi Friend, Pleas visit the following link:ADS_TO_REPLACE_1 Automorphic numbers Thanks

PRIME AND EVEN AND ODD how to write prime numbers?i want source code? how to write even numbers? i want source code? how to write odd numbers ?i... + " "; } } } System.out.println(primeNo); } } 2) Following code displays Even and Odd numbers

sorting numbers How to sort the numbers in ascending order import java.util.*; class SortNumbers{ public static void main(String...=input.nextInt(); list.add(num); } System.out.println("Numbers

Prime Numbers Create a complete Java program that allows the user to enter a positive integer n, and which then creates and populates an int array with the first n prime numbers. Your program should then display the contents

JSTL - check odd/even number How do i create a JSTL program to generate random numbers and to check whether they are odd/even and print "this is an even (odd) number and it is in between so and so number? e.g. the random number

Numbers pyramid Hi sir, Can you please tell me how to output this using nested for loops? 1 2, 1 1, 2, 3 4, 3, 2, 1 1, 2, 3, 4, 5 6, 5, 4, 3, 2, 1 1, 2, 3, 4, 5, 6, 7 8, 7, 6, 5, 4, 3, 2, 1 1, 2, 3, 4, 5, 6, 7, 8, 9 10, 9, 8

Rational Numbers Write and fully test a class that represents rational numbers. A rational number can be represented as the ratio of two integer values, a and b, where b is not zero. The class has attributes for the numerator

ModuleNotFoundError: No module named 'even_detector' Hi, My... 'even_detector' How to remove the ModuleNotFoundError: No module named 'even_detector' error? Thanks Hi, In your python

ModuleNotFoundError: No module named 'even_detector' Hi, My... 'even_detector' How to remove the ModuleNotFoundError: No module named 'even_detector' error? Thanks Hi, In your python

ModuleNotFoundError: No module named 'even-tester' Hi, My Python... 'even-tester' How to remove the ModuleNotFoundError: No module named 'even-tester' error? Thanks Hi, In your python environment

Hexadecimal numbers multiplication Sir, I have to multiply 128 bit hexadecimal numbers. Do u have any logic for this?? The numbers are like ab7564fa342b5412c34d9e67ab341b58

defining numbers in Java Script Explain about defining numbers in Java Script

ModuleNotFoundError: No module named 'numbers' Hi, My Python... 'numbers' How to remove the ModuleNotFoundError: No module named 'numbers... to install padas library. You can install numbers python with following command

multiply of 100 digits numbers multiplying 100 digits numbers to eachother

numbers divisible by 5 and 6 Find the first ten numbers which are greater than Long.MAX_VALUE divisible by 5 and 6

prime numbers Write a java program to find the prime numbers between n and m

Generate Random Numbers hi,,, Please give me answer with example How do you generate random numbers within a given limit with actionscript... This function generate random numbers with in given limit

random numbers write a program to accept 50 numbers and display 5 numbers randomly Hi Friend, Try the following code: import...); System.out.println("Enter 10 numbers: "); for(int i=0;i<10;i

odd numbers with loop get the odd numbers till 100 with for,while loop Java find odd numbers: class OddNumbers { public static void main(String[] args) { for(int i=1;i<=100;i

even more circles Write an application that compares two circle objects. ? You need to include a new method equals(Circle c) in Circle class. The method compares the radiuses. ? The program reads two radiuses from the user

in this coding even backspace key and enter key should accept.... in this coding even backspace key and enter key should accept....plez help me...{ JOptionPane.showMessageDialog(null, "Only numbers are allowed

recursion numbers I need to use recursion to test all values from 0 to 20 and see if they are contain in a 1-D array with values: 2,4,6,8,10,12,14,16,18,20. The results of all numbers from 0-20 will be printed

; import java.util.*; class Numbers { public static void main(String...=0,sum2=0; int num[]=new int[10]; System.out.println("Enter 10 numbers...]; } } System.out.println("Sum of positive numbers: "+sum2); System.out.println

Application for print pyramid of numbers What is the code for printing the numbers like 1 1 1 1 2 2 1 1 3 4 3 1 1 4 7 7 4 1

Sum of first n numbers i want a simple java program which will show the sum of first n numbers.... import java.util.*; public class...; } System.out.println("Sum of Numbers from 1 to "+n+" : "+sum

to display the random numbers, but not twice or more. I mean i need a number to be display once. This code allows some numbers to be displayed more than once. Hi... Scanner(System.in); System.out.println("Enter 10 numbers: "); for(int i=0;i<10;i

Prime Numbers Create a program that calculates the prime numbers... numbers in rows of 10. Hint: Use a counter to count how many values are printed... = 0; System.out.println("Prime Numbers are:" ); for (int i = 1; i <

print the sum of even number from 1 to 100 how to print the sum of even number from 1 to 100 using for loops? Thanks

Odd Even Transposition Sort In Java ... In this example we are going to sort integer values of an array using odd even transposition sort. Odd even transposition sort is a parallel sorting algorithm. Odd Even

Java program - convert words into numbers? convert words into numbers? had no answer sir

convert numbers to strings using JavaScript How to convert numbers to strings using JavaScript

Generating random numbers in a range with Java Generating random numbers in a range with Java

ModuleNotFoundError: No module named 'does-this-even-work-anymore' ...: No module named 'does-this-even-work-anymore' How to remove the ModuleNotFoundError: No module named 'does-this-even-work-anymore' error? Thanks

ModuleNotFoundError: No module named 'even-more-itertools' Hi, My... named 'even-more-itertools' How to remove the ModuleNotFoundError: No module named 'even-more-itertools' error? Thanks Hi

Ads