janesa
odd and even
1 Answer(s)      2 years and 6 months ago
Posted in : Java Beginners

how can i make a program of even and odd using case statement?

View Answers

November 20, 2010 at 2:32 PM


Hi Friend,

Try the following code:

import java.util.*;
public class EvenOddExample{
    public static void main(String[]args){
        boolean status=false;
    Scanner input=new Scanner(System.in);

        System.out.println("Enter Numbers: ");
    int arr[]=new int[10];
    for(int i=0;i<arr.length;i++){
        arr[i]=input.nextInt();
    }

    do{
        System.out.println();
    System.out.println("1 Display Even");
    System.out.println("2 Display Odd");
    System.out.println("3 Exit");
    System.out.print("Choose Option: ");
    int choice=input.nextInt();
    switch(choice){
    case 1: 
        for(int i=0;i<arr.length;i++){
        if(arr[i]%2==0){
            System.out.println(arr[i]);
            }
        }
        break;
        case 2:
            for(int i=0;i<arr.length;i++){
            if(arr[i]%2!=0){
         System.out.println(arr[i]);
            }
        }
        break;
        case 3:
            status=true;
            System.exit(0);
        break;
        }
    }
    while(!status);
    }
}

Thanks









Related Pages:
odd and even
odd and even  how can i make a program of even and odd using case...{ System.out.println(); System.out.println("1 Display Even"); System.out.println("2 Display Odd"); System.out.println("3 Exit"); System.out.print("Choose
Even and odd functions in java
Even and odd functions in java  Even and odd functions in java  ... have two separate functions for checking either number is even or odd. We...); int number; System.out.println("Input any number to check even
Check even or odd number.
Check even or odd number.  How to check given number is even or odd?   Simple if it is devided by 2 it is even and if not if is Odd  ...){ System.out.println("Number is Even"); } else
JSTL - check odd/even number - JSP-Servlet
JSTL - check odd/even number  How do i create a JSTL program to generate random numbers and to check whether they are odd/even and print "this is an even (odd) number and it is in between so and so number? e.g. the random number
PRIME AND EVEN AND ODD - Java Interview Questions
PRIME AND EVEN AND ODD  how to write prime numbers?i want source code? how to write even numbers? i want source code? how to write odd numbers ?i... + " "; } } } System.out.println(primeNo); } } 2) Following code displays Even and Odd numbers
Odd Even Transposition Sort In Java
Odd Even Transposition Sort In Java   ... In this example we are going to sort integer values of an array using odd even transposition sort. Odd even transposition sort is a parallel sorting algorithm. Odd Even
Check whether highest number is even or odd
Check whether highest number is even or odd In this section, you will learn... it is odd or even. For this, we have taken two integer variables num1 and num2... that if the highest number is totally divided by 2,then it is even, otherwise
Calculate sum of even and odd numbers in Java
Calculate sum of even and odd numbers In this section, you will learn how to read the file that contains even and odd numbers and calculate their sum separately. To do this, first of all, we have found all the even and odd numbers from 1
Check Even-Odd:-Example
Check Even-Odd:-Example     ... reads a integer value and check weather number is Odd or Even. In this example you will learn how to determine the Even or Odd for the given number entered
odd numbers with loop
odd numbers with loop  get the odd numbers till 100 with for,while loop   Java find odd numbers: class OddNumbers { public static void main(String[] args) { for(int i=1;i<=100;i
Mysql Mod
Mysql Mod       Mysql Mod (a,b) is performed to return remainder  when b is divided by a. Incase you use MOD(a, 3) you get 1 for even numbers and 0 for odd numbers. If you use
EVEN NUMBERS - Java Interview Questions
EVEN NUMBERS  i want program of even numbers?i want source code plz reply?  Hi Friend, Try the following code: class EvenNumbers... counter = 0; System.out.println("Even Numbers are:" ); for (int i
even more circles - Java Beginners
even more circles  Write an application that compares two circle objects. ? You need to include a new method equals(Circle c) in Circle class. The method compares the radiuses. ? The program reads two radiuses from the user
print the sum of even number from 1 to 100
print the sum of even number from 1 to 100  how to print the sum of even number from 1 to 100 using for loops? Thanks
print the even numbers between the range 100-200
print the even numbers between the range 100-200  Q ?write an application that print out the even numbers between the range 100-200 ? 1- which aer... prints out the even numbers between the range of 100 and 200 and then determine
log4j is not logging even under src path
log4j is not logging even under src path  We are working with struts application and using log4j.properties file , it is placed under WEB-INF/classes and we have referenced log4j-1.2.8.jar in classpath file even after
Java write even numbers to file
Java write even numbers to file In this section, you will learn how to write the even numbers to file. By using the PrintWriter class, you can write any type... leaving 0 remainder, then it should be an even number and stored in the file. We
NoSuchMethodException even if method defined - Java Beginners
NoSuchMethodException even if method defined  Hi I am loading a class (Student) dynamically from a jar (samplejar.jar) file using URLClassLoader. Next thing when I want to access method or constructor of the previously loaded
Display Hello even before main get executed??
Display Hello even before main get executed??  I have a class (main method) as follow.....As I know this can be done using static method, but Q is how? **class Hello{ public static void main(String[] args
write an application that print out the even numbers between the range 100-200
write an application that print out the even numbers between the range 100-200   write an application that print out the even numbers between... and determine the even numbers between them. class EvenNumbers { public static
in this coding even backspace key and enter key should accept....
in this coding even backspace key and enter key should accept....   in this coding even backspace key and enter key should accept....plez help me and make changes to which it accept backspace and enter key ....plez plez plez its
How does this example work even if no oracle to be used and only access is available?
How does this example work even if no oracle to be used and only access is available?  CONNECTION CLASS package ExamplePackage; import java.sql.*; import java.util.*; public class ConnectionManager { static Connection
Write a program to list all even numbers between two numbers
Write a program to list all even numbers between two numbers       Java Even Numbers - Even... all the even numbers between two numbers. For this first create a class named
Java
Java  Write a program that repeatedly reads an integer from the console. If the integer is odd, outputs "Odd Day" if the integer is even (and not 0), outputs â??Even now". if the integer is 0. exits program
how to make session valid even browser has closed - Java Interview Questions
how to make session valid even browser has closed  Hi, I have doubt that session will close when we close the web browser. My doubt is, even when I close the browser my session should not close or delete. How can I do
why above code returning the value of squares is 82... even after returning an increnented value of squares... please help me...
why above code returning the value of squares is 82... even after returning an increnented value of squares... please help me...   public class d55 { int squares = 81; public static void main(String
Scheduler triggering cron jobs multiple times at the scheduled time and job is retained even after deleting
Scheduler triggering cron jobs multiple times at the scheduled time and job is retained even after deleting  In our application we are using quartz... multiple times with an interval of few miliseconds at the scheduled time. Even
java
java   How to find out whether a given input is a odd number or even number
Error in reading Excel data using jsp even having .xls and POI Library in respective folders
Error in reading Excel data using jsp even having .xls and POI Library in respective folders  Hi, hello.xls and POI library files are there in respective folders. the printStackTrce() method shows the following Error message
retaining save dialog box even after clicking save button - Java Beginners
retaining save dialog box even after clicking save button  I am building an apllication.In that i need to save a text typed in text area to a file.so... get it back??(even if i cal save dialog box again it would open again from
java program13
java program13  Write a java propgram to find the list even and odd... even=" ",odd=" "; Scanner input=new Scanner(System.in...++){ if(i%2==0){ even+=i+" "; } else{ odd
java programming
) with a statement indicating whether it is even or not.. Output: Example Number 0 - Even Number 1 - Odd Number - 2 Even . . . Number 999 - Odd
Loops
Loops  Write a program that repeatedly reads an integer from the console. If the integer is odd, outputs ââ?¬Å?Odd Day!ââ?¬Â? if the integer is even (and not 0), outputs ââ?¬Å?Even now!ââ?¬Â?. if the integer is 0. exits
In Java..
if the value is even or odd. If the data is even the tester class should call... is odd. You should also have an Odd method which does the same thing as the Even... the even and odd averages
java progaram - Java Beginners
and display the odd and even numbers of the list separately   Hi Friend, Try... void main(String[]args){ String even=""; String odd=""; for(int i=1;i<=50;i++){ if(i%2==0){ even+=i+" "; } else{ odd+=i
program coding
program coding  how to rearrange the array a[1]. . a[n] even elements and odd elements? please give the example coding program
program coding
program coding  how to rearrange the array a[1]. . a[n] even elements and odd elements? please give the example coding program.please provide the coding for this problem
How to program an application for? - Java Beginners
to count the number of both odd and even integers of several positive integerss? Then the final display is the total of how many odd numbers were entered and the total of how many even numbers were entered?  Hi Friend, Try
Printing the integers before and after - JSP-Servlet
it as either even or odd, but it does not seem to work. Pls advise on my code below... is It is an even number lies between and It is an odd number lies between...} <c:if test="${luckyN}%2==0">It is an even number and it is between
program coding
program coding  write a c program to rearrange the array a[1]. . .a[n] in such a way that all even elements precede all odd elements (not changing the order inside each of the two groups
help pleas? -_-
help pleas? -_-  Write a Java program that reads from the user an integer N followed by N integers. The program then prints the product of odd integers, and, the sum of even integers
the question make me so blur
the question make me so blur  write java code that read an integer and determine and print whether it is odd or even.(Hint: use the remainder operator.An even number is a multiple of 2. Any multiple of 2 leaves a remainder of 0
java code - Java Beginners
reads an integer from the user and determines whether it is odd or even  reads an integer from the user and determines whether it is odd or even ... and determines whether it is odd or evenimport java.io.*;class Test{ public static void
java beginnerssss!!!
rather it is even or odd if both entries are even then multiply both vaalue and if both are odd then bigger term minus from lesser and if one even and one entry is odd then the msg display is wrong entry   Hi Friend, Try
Sum of integers
the user and displays i) the sum of all even integers between 1 and the input value, both inclusive. ii) The sum of all odd integers between 1 and the input value both inclusive Example: User enters 7. Sum of even integers = 2+4+6 = 12 Sum
File - Java Beginners
appended to the file (the even numbers are in front, followed by the odd numbers... an algorithm that adds all even numbered integers from 1 to 100, separated... the results to the screen. After the results have been displayed append the odd
To find the reminder for a double - JSP-Servlet
To find the reminder for a double  Dear sir , How to find the reminder for a 0.5%0.1.When i do this it is giving 0.09999999999999998 .it is giving correct zero reminder for even numbers for odd numbers it is giving
while loop to for loops
numbers and sum of even numbers System.out.print("Odd Numbers...){ if (currentNum % 2 == 0){ System.out.print("Even numbers: "+currentNum); } else{ System.out.print("Odd numbers
Java number calculation using while loop
must be less than secondNum.) and output all the odd numbers between firstNum and secondNum inclusive. It also find the sum of all the even numbers between... the odd numbers between firstNum and secondNum inclusive. Example: import
JAVA - Java Beginners
variables,test whether the higest number is even or odd  Hi Friend, Try... "+highestNumber+" is Even"); } else{ System.out.println("Highest Number "+highestNumber+" is Odd"); } } } Thanks

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.