Declare multiple variables in for loop Example

  1. /*
  2.   Declare multiple variables in for loop Example
  3.   This Java Example shows how to declare multiple variables in Java For loop using
  4.   declaration block.
  5. */
  6.  
  7. public class DeclaringMultipleVariablesInForLoopExample {
  8.  
  9. public static void main(String[] args) {
  10.  
  11. /*
  12.   * Multiple variables can be declared in declaration block of for loop.
  13.   */
  14.  
  15. for(int i=0, j=1, k=2 ; i<5 ; i++)
  16. System.out.println("I : " + i + ",j : "+ j + ", k : " + k);
  17.  
  18. /*
  19.   * Please note that the variables which are declared, should be of same type
  20.   * as in this example int.
  21.   */
  22.  
  23. //THIS WILL NOT COMPILE
  24. //for(int i=0, float j; i < 5; i++);
  25. }
  26. }

can you help!??

how will i make a code producing an output like this:
*****
****
***
**
*
???

piramid code

  1. for (int i = 5; i > 0; i -= 2) {
  2. for (int j = 0; j < i; j++) {
  3. System.out.print('*');
  4. }
  5. System.out.println();
  6. }

I can help

  1. void makePyramid()
  2. {
  3. for (int i = 0; i < 5; i++)
  4. {
  5. for (int j = i; i < 5; j++)
  6. System.out.print('*');
  7. System.out.println();
  8. }
  9. }

can you please help me?

Could you give me the code of this output:
*
**
***
****
*****
******
*******
******
*****
****
***
**
*

Like so

  1. for(int i=5; i>0; i--){
  2. for(int x=0; x<i; x++{
  3. System.out.print("*");
  4. }
  5. if(i!=1) System.out.println();//avoid printing line if final output
  6. }

second for loop will never

second for loop will never end
change it to

  1. for(int j=i ; j<5 ; j++)

Code From Highest Number

Write a program that displays 3 integers then displays the highest number..

help please

how can i make an output like this?
3
4
6
9
13
18
24

help me plz??

how will i make a code producing an output like this:
*
**
***
****
*****

What is the code for this?

how can you make this? please i need to know.. thanks...
*********
**** ****
*** ***
** **
* *
** **
*** ***
**** ****
*********

how can i do this?

0 + 0 = 0
1 + 2 = 3
2 + 4 = 6
3 + 6 = 9
4 + 8 = 12
5 + 10 = 15
6 + 12 = 18
7 + 14 = 21
8 + 16 = 24
9 + 18 = 27

solution to the above sequence addition

  1. public class PrintSequenceAddition {
  2.  
  3. public void createSeq(){
  4. for(int i=0; i<=9; i++){
  5. System.out.println(i +"+" +(i*2) +"=" +(i + (i*2)));
  6. }
  7. }
  8.  
  9. public static void main(String[] args) {
  10. PrintSequenceAddition psa = new PrintSequenceAddition();
  11. psa.createSeq();
  12. }
  13. }

how to make a code showing this

*
*
*
*
*
please answer

how about making a diamond

1
2 2
3 3 3
4 4 4 4
3 3 3
2 2
1

What is the output for this??

######
#####
####
###
##
#

Thanks!!

What is the code that make output like below??

######
#####
####

###
##
#

Here is the solution

  1. public class JavaPyramid2 {
  2.  
  3. public static void main(String[] args) {
  4.  
  5. for(int i=5; i>0 ;i--){
  6.  
  7. for(int j=0; j < i; j++){
  8. System.out.print("#");
  9. }
  10.  
  11. //generate a new line
  12. System.out.println("");
  13. }
  14. }
  15. }

What is the code that make output like below??

************
***** ******
**** ****
*** ***
** **
* *
** **
*** ***
**** ****
***** ******
************

help me

1
1 2
1 2 3

palindrome

how to produce this output?
Enter a string: abba
The reverse of the entered string is abba.
The entered strig is a palindrome

how to display tis

K
SADV

SDVSVD
XSDVSDFV
SD
SDFSDFGSDGH
FN FH
FMTH
GFHF
MHF
FY
F
FTT
YF
JYF
TY
FTY

how can i

How can I do this?

1
212
32123
4321234
543212345
65432123456
etc?

Need Help

I have to loop a program containing if statements, 3 times. a double has to be input by the user and the output has to show either POSITIVE, NEGATIVE or ZERO>

Please help

how i find given sis pseudo arithmetic series or not:2,5,6,8,9

pls give solution in java

Please help! How do I print this?

Using a for loop:
1 4 7 10 13 16 19 22 25 28 31 34 37 40

Should count to 40 by 3's. Thank you!!

pure amazement

you are amazing the way u pop out code

diamond..........

*
***
*****
*******
*****
***
*

Post new comment

To combat spam, please enter the code in the image.


Suggested Reading

Oracle Magazine
Contains technology strategy articles, sample code, tips, Oracle and partner news, how to articles for developers and DBAs, and more.
Cost: FREE

View/Subscribe
NASA Tech Briefs
Features exclusive reports of innovations developed by NASA and its industry partners/contractors that can be applied to develop new/improved products and solve engineering or manufacturing problems.
Cost: FREE

View/Subscribe
FierceBiotech IT
Is a free, easy to read weekly email service that brings must read biotech IT news to senior biotech, pharma, and IT executives.
Cost: FREE

View/Subscribe
Simply SQL
Simply SQL is a practical step-by-step guide to writing SQL.
Cost: FREE

View/Subscribe
Simply JavaScript
Packed with full-color examples, Simply JavaScript is all you need to start programming in JavaScript the right way.
Cost: FREE

View/Subscribe
PCMag.com's What's New Now
Lance Ulanoff, Editor in Chief of the PC Magazine Network, brings you this twice-weekly roundup of the latest top tech stories, the best new product reviews, plus special offers from Ziff Davis and its partners.
Cost: FREE

View/Subscribe

Could not find what you are looking for? Search Java Examples




Feel Tired? Read Jokes & Inspirational Stories, Play Games!