![]() |
|
|
|
| ||||||
|
Welcome to the The ProgrammersTalk Community forums. You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today! If you have any problems with the registration process or your account login, please contact contact us. |
| Tags: |
![]() |
![]() | | LinkBack | Thread Tools | Display Modes | ![]() |
| |||
| [SOLVED] java program....? 4.(programming) Write a program OddElements that creates an int array containing the odd integers from 51 to 99 and then prints the array elements with 5 elements per line. So the output should be: 51 53 55 57 59 61 63 65 67 69 71 73 75 77 79 81 83 85 87 89 91 93 95 97 99 You must use one for loop to initialize (populate) the array and another for loop to print the elements. |
| |
| |||
| class OddElements { public static void main( String[] a ) { int [] t = new int[ 50 ]; for( int i =0;i<t.length; i++) t[ i ] = i+51; for( int i=0; i<t.length; i++) { if ( t[ i ] % 2 == 1) { System.out.print( t[ i] + " "); } if( i %5 == 0 ) System.out.print( "\n" ); } } } |
![]() |
| Thread Tools | |
| Display Modes | |
| |