Java - Print odd number using for loopHOME Java Statement for Statement Description Print odd number using for loop Demo public class Printoddnumber { public static void main(String[] args) { int x;/*from w w w . j a va 2s .c om*/ for (int i =1 ; i<10; i=i+2) { ...
There are several ways to print an array in Java. Here are a few options: Using a loop: int[] array = {1, 2, 3, 4, 5}; for (int i = 0; i < array.length; i++) { System.out.print(array[i] + " "); } Using the Arrays.toString() method: import java.util.Arrays; ...
int array[] = {6, 5, 4, 3, 2, 1}; n = sizeof(array)/sizeof (array[0]); for_each(array, array+n, printMyArr); return 0; } Output: 6 5 4 3 2 1 print array in C++ Using Range-Based for Loop C++11 introduced a new concept of the range-based for loop, that is far...
If you are using Python 2.x then you can import print function as below: 1 2 3 from __future__ import print_function Using loop Here, for loop is used to iterate through every element of an array, then print that element. We can also use while loop in place of for loop. Below...
The loop automatically iterates over each element in the collection, and the specified code block is executed for each iteration. Let’s consider a scenario where we have a list of strings and want to print each string using the enhanced for loop. import java.util.Arrays; import java.util....
In Java, every ArrayList has aforEachmethod, which is one of the simplest ways to loop through all the items just like theforloop. Like the previous example, we can get the names fromModelClassusing thegetName()method. importjava.util.ArrayList;importjava.util.Arrays;importjava.util.function...
Prints an array of characters. The characters are converted into bytes according to the platform's default character encoding, and these bytes are written in exactly the manner of the#write(int)method. Java documentation forjava.io.PrintWriter.print(char[]). ...
//package com.java2s; public class Main { public static void main(String[] argv) throws Exception { byte[] byteArray = new byte[] { 34, 35, 36, 37, 37, 37, 67, 68, 69 }; printByteArray(byteArray);/*from ww w.jav a2 s . c om*/ } public static void printByteArray(byte...
JavaObject Oriented ProgrammingProgramming You can simply iterate the byte array and print the byte using System.out.println() method. Example public class Tester { public static void main(String[] args) { byte[] a = { 1,2,3}; for(int i=0; i< a.length ; i++) { System.out.print...
This is a Java Program to Print the Odd & Even Numbers in an Array. Enter size of array and then enter all the elements of that array. Now using for loop and if codition we use to distinguish whether given integer in the array is odd or even. ...