Answers for "java program that will display middle number if even print 2 numbers is odd print return"

1

Java code to print odd number

class JavaExample {
   public static void main(String args[]) {
	int n = 100;
	System.out.print("Odd Numbers from 1 to "+n+" are: ");
	for (int i = 1; i <= n; i++) {
	   if (i % 2 != 0) {
		System.out.print(i + " ");
	   }
	}
   }
}
Posted by: Guest on August-19-2021
0

Java program to print odd and even numbers between 1 and 100

// Java program to print odd and even numbers between 1 and 100
public class EvenOddBetween1And100
{
   public static void main(String[] args)
   {
      System.out.println("Even numbers between 1 and 100: ");
      for(int a = 1; a <= 100; a++)
      {
         if(a % 2 == 0)
         {
            System.out.print(a + " ");
         }
      }
      System.out.println("\nOdd numbers between 1 and 100: ");
      for(int a = 1; a <= 100; a++)
      {
         if(a % 2 != 0)
         {
            System.out.print(a + " ");
         }
      }
   }
}
Posted by: Guest on February-22-2021

Code answers related to "java program that will display middle number if even print 2 numbers is odd print return"

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language