Common

How do you print the first 20 odd numbers in Java?

How do you print the first 20 odd numbers in Java?

  1. import java. util. *;
  2. public static void main(String[] args) {
  3. Scanner sc = new Scanner(System. in);
  4. System. out. println(“Enter a no”);
  5. int n = sc. nextInt();
  6. System. out. println(“First “+n+” ODD nos”);
  7. for(i=1;i<=2*n;i++)
  8. if(i\%2 == 0)

How do you print odd numbers only in Python?

To print odd numbers from a list of numbers you can use the Python modulo operator, related to the mathematical concept of remainder. When you divide an odd number by 2 the remainder of the division is 1. When you divide an even number by 2 the remainder of the division is 0.

How do you show even and odd numbers in Java?

Java Program to print Odd and Even Numbers from an Array

  1. public class OddEvenInArrayExample{
  2. public static void main(String args[]){
  3. int a[]={1,2,5,6,3,2};
  4. System.out.println(“Odd Numbers:”);
  5. for(int i=0;i
  6. if(a[i]\%2!=0){
  7. System.out.println(a[i]);
  8. }
READ ALSO:   Is Rough ER single membrane?

How do you write odd numbers in Python?

See this example:

  1. num = int(input(“Enter a number: “))
  2. if (num \% 2) == 0:
  3. print(“{0} is Even number”. format(num))
  4. else:
  5. print(“{0} is Odd number”. format(num))

Is odd program in Java?

Now, to check whether num is even or odd, we calculate its remainder using \% operator and check if it is divisible by 2 or not. If num is divisible by 2 , we print num is even. Else, we print num is odd. We can also check if num is even or odd by using ternary operator in Java.

How do you show odd numbers in Java?

Java program to display odd numbers between 1 -100

  1. package com. candidjava. code;
  2. class OddNumber {
  3. public static void main(String args[]) {
  4. System. out. println(“The Odd Numbers are:”);
  5. for (int i = 1; i <= 100; i++) {
  6. if (i \% 2 != 0) {
  7. System. out. print(i + ” “);
  8. }