BJ
loop problem
1 Answer(s)      4 years ago
Posted in : Java Beginners

View Answers

June 2, 2009 at 10:15 AM


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);
}
}

Hope that it will help you.

Thanks









Related Pages:
loop
loop  strong textHello can someone help me with this problem,I need to output the following code using a loop the code is as follows with the user inputs in inverted commas,thanks. ENTER CODE(XX to Stop) CODE:"D24" QUANTITY:"2
loop problem - Java Beginners
loop problem  I trying to write a program which prints out even numbers, I've got that part, however, I need to only have 5 numbers per line. ex: 2 4 6 8 10 12 14 16 18 20 I tried using a counter, but I'm missing
loop problem - Java Magazine
loop problem  import java.util.Scanner; class mychoice{ public static void main(String[] args){ Scanner choice = new Scanner(System.in... to main menu to select new item. //what loop to use? break
Javascript Loop Error - WebSevices
Javascript Loop Error  ...(); Error: Only if loop will executed, Does not comes to else if part. So tell... there is no "else if" part.Plz give details full code and problem in details. Thanks
Until Loop In a Procedure
Beginners trapped with the problem of  execution of loop... Until Loop In a Procedure       Until Loop In a Procedure is used to execute a set of statements
While loop - Java Beginners
While loop  Given a number, write a program using while loop to reverse the digits of the number. Eg. the no. is 12345, should be written as 54321.  Hi friend, Code to solve the problem : import java.io.*; class
loop
loop  what is the difference b/w do while,while and for loop..with example
loop
loop  i want to write my name(inder) through loop in java using star
for loop
for loop  what is for loop   Loops are used for iteration... for a number of times it is finite loop and if repetition is done infinitely it is infinite loop. Java provides several loop structures for iteration. Those
For loop
For loop  Hi! Please explain the following loop: for(i=0;i<a[j];i++) THANX!!   Please reply as soon as possible
prepared statement in for loop - JDBC
prepared statement in for loop  Hi all, I am reding data from a jsp page and inserting into a table. For this i am using prepared statement in a for loop. But my problem is that only one row is getting inserted
for loop
for loop  how to performs the for loop when 2 inputs given like displays the triangle shape and how to take initial values or declaration values plz explain in detailed ex. 1 12 123 1234
Loop
to understand a loop my quesiton are: what du i do wrong in my code since.... (made in blueJ) Class Loop public void loopUpGeneral(int start, int stop... dk  Hi, Please check the for loop once again: for (int i
For Loop
For Loop  Write a program using a for loop that computes the following sum: 1/2 + 2/2 + 3/2 + 4/2 + 5/2 + ... N/2 N will be an integer limit the user enters. This is an example of my upcoming quiz. I need help on knowing
for loop
for loop  using only two for loop how can print below numbers 1 2 2 3 3 3 4 4 4 4 5 5 5 5 5 6 6 6 6 6 6 7 7 7 7 7 7 7 8 8 8 8 8 8 8 8 9 9 9 9 9 9 9 9 9 8 8 8 8 8 8 8 8 7 7 7 7 7 7 7 6 6 6 6 6 6 5 5 5 5
for loop
for loop  using only two for loop how can print below numbers 1 2 2 3 3 3 4 4 4 4 5 5 5 5 5 6 6 6 6 6 6 7 7 7 7 7 7 7 8 8 8 8 8 8 8 8 9 9 9 9 9 9 9 9 9 8 8 8 8 8 8 8 8 7 7 7 7 7 7 7 6 6 6 6 6 6 5 5 5 5
Problem with arraylist
Problem with arraylist  I am currently working on a java project and there is an if loop within the for loop.... for(int i = 1;i < iterationsNo... and clusterMean1 are not equal and so the the statements insdie the if loop must
Java I/O Assistance + Loop
peers to no luck. I now come here in hopes of assistance. the problem is within my loop I believe I just cant wrap my head around how to get a proper display...(new FileWriter(outFile)); //This for loop handles adding all
Two Indexes in For Loop
use two indexes in a for loop. We can solve this problem by using for loop...Two Indexes in For Loop     ...; FIndex <= 5; FIndex++, otherIndex = 2 + FIndex) In this for loop we are taking
Until Loop In a Procedure
Beginners trapped with the problem of  execution of loop... Until Loop In a Procedure       Until Loop In a Procedure is used to execute a set of statements
While loop break causing unwanted output
While loop break causing unwanted output  Below I will paste my code. My problem is that when I run this I get to input a int and if correct it will output that I was correct but after that it will output something that I'm
Loop Idioms
number of times. Loop over a String using an index A common problem is move... of tasks, so many loops tend to be one of several common styles. Loop reading input It's very common to read input in a loop: read a value, process it, go back
help me to solve this problem..
help me to solve this problem..  Given below is a class definition for Book. Type and compile the class, and answer the following questions: class... and then create an array name myLibrary of type Book with size n. Using loop, create n
For..in loop
For..in loop         In this tutorial we will study for..in loop which is similar to for each loop of C#, Java and other popular languages, in this example
loop gymnastics,new for in loop gymnastics,result set Iterable,java newsletter,tutorial
New for/in loop gymnastics 2005-02-07 The Java Specialists' Newsletter [Issue 103] - New for/in loop gymnastics Author: Dr. Heinz M. KabutzJDK version.... New for/in loop gymnastics The new for/in loop gives us
Bid Problem - Java Beginners
Bid Problem  Write a 'for' loop to input the current meter reading... in the bill)   Hi friend, What the requirement of "for" loop in this application explain in details : Code to help in solving the problem
code problem - Java Beginners
code problem  Dear sir, i'm making a program where characters of a string are being displayed having its length thru a loop, like- s a t i s h i want to store them as sequence in a StringBuffer like "satish" how
Java for loop
Java for loop  Can a for statement loop indefinitely
Running problem with NoughtsAndCrossesGame in blank
Running problem with NoughtsAndCrossesGame in blank  Hi i was having problem created NoughtsAndCrossesGame in end the it works but i runs the gui... in the above loop but is shown separately here to make
DiceRolls excersise problem
for loop. Modify the DiceRolls application to prompt the user for the number
DiceRolls excersise problem
for loop. Modify the DiceRolls application to prompt the user for the number
Form Processing Problem
; //this loop converting the uploaded file into byte code...; <% } %> </table> </html> The problem while
Very Big Problem - Java Beginners
Very Big Problem  Write a 'for' loop to input the current meter... to give in the bill) It is asked by my teacher to write a 'for' loop for this question otherwise I was myself able to write an if-else loop for this question
arraylist problem - JSP-Servlet
arraylist problem  hello thanx a lot for ur reply. i m sending u my code once again only in which i m facing the problem. /* * To change...() || rs_counter8.hasNext()) using loop you iterate the element Thanks
For Loop - Struts
For Loop  Hi, How to use for loop in Struts2. I don't want use.... How to use the For loop in JSP. Thanks, Rajesh.  Hi Rajesh, i am sending simple use of for loop. In this example, you will see the use
for( ) loop in php
for( ) loop in php  Generally, when we use for loop in PHP or any other programming language why we use i++ and not ++i. What is the reason behind
for( ) loop in php
for( ) loop in php  Generally, when we use for loop in PHP or any other programming language why we use i++ and not ++i. What is the reason behind
Limits of "For loop"
Limits of "For loop"  Hi, How can I check the upper limit and lower limit of 'FOR' loop during unit testing using Junit. Thanks & Regards Ankit
How to write a loop and a while loop
How to write a loop and a while loop  How do I write a 1 loop and a 1 while loop for the example code: public boolean isTheFirstOneBigger (int num1, int num2) { if (num1 > num2) { return true
loop statements
loop statements  write a program that reads from input an interger n and prints the factorial of all numbers between 1 and n
problem in java code - Java Beginners
problem in java code  In displaying an matrix in normal java code we use two for loops...When i attended an interview.....the hr asked me to display the matrix by only using one loop....there should be any condition or other
for loop in java
for loop in java  54321 4321 321 21 1 using for loop or nested 1 1 2 1 2 3 1 2 3 4 1 2 3 4 5 5 4 3 2 1 4 3 2 1 3 2 1 2 1 1 using for loop or nested... 8 9 6 7 8 9 10 all for loop code plz friends guide me
for loop in java
for loop in java  54321 4321 321 21 1 using for loop or nested 1 1 2 1 2 3 1 2 3 4 1 2 3 4 5 5 4 3 2 1 4 3 2 1 3 2 1 2 1 1 using for loop or nested... 8 9 6 7 8 9 10 all for loop code plz friends guide me
for loop in java
for loop in java  54321 4321 321 21 1 using for loop or nested 1 1 2 1 2 3 1 2 3 4 1 2 3 4 5 5 4 3 2 1 4 3 2 1 3 2 1 2 1 1 using for loop or nested... 8 9 6 7 8 9 10 all for loop code plz friends guide me
loop example
loop example   1 1 2 1 2 3 1 2 3 4 1 2 3 4 5 can you give me the code to get the number pyramid
for loop in java
for loop in java  54321 4321 321 21 1 using for loop or nested 1 1 2 1 2 3 1 2 3 4 1 2 3 4 5 5 4 3 2 1 4 3 2 1 3 2 1 2 1 1 using for loop or nested... 8 9 6 7 8 9 10 all for loop code plz friends guide me
for loop in java
for loop in java  54321 4321 321 21 1 using for loop or nested 1 1 2 1 2 3 1 2 3 4 1 2 3 4 5 5 4 3 2 1 4 3 2 1 3 2 1 2 1 1 using for loop or nested... 8 9 6 7 8 9 10 all for loop code plz friends guide me
For Loop/PHP
For Loop/PHP  Write a class called math. It is to have one property... 12345. How would you write this as a loop? Would I need to use the for loop or do/while loop?   PHP Factorial Example: <?php $n = 5; $i = 1; $f

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.