How to find the given no is odd or even without checking of
any condition and loops. (Hint: Using array)

Answer Posted / amala v

import java.io.*;
public class even {
public static void main(String arg[])throws
IOException
{
String a[]={"even","odd"};
BufferedReader br=new BufferedReader(new
InputStreamReader(System.in));
int n;
System.out.println("Enter no to find");
n=Integer.parseInt(br.readLine());
n=n%2;
System.out.println("given no is "+a[n]);

}

}

Is This Answer Correct ?    12 Yes 3 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What would be an example of a structure analogous to structure c?

578


Why c is a procedural language?

587


Explain what are run-time errors?

614


What is FIFO?

678


What are pragmas and what are they good for?

580






What is a structure member in c?

552


c program for searching a student details among 10 student details

1660


You have given 2 array. You need to find whether they will create the same BST or not. For example: Array1:10 5 20 15 30 Array2:10 20 15 30 5 Result: True Array1:10 5 20 15 30 Array2:10 15 20 30 5 Result: False One Approach is Pretty Clear by creating BST O(nlogn) then checking two tree for identical O(N) overall O(nlogn) ..we need there exist O(N) Time & O(1) Space also without extra space .Algorithm ?? DevoCoder guest Posted 3 months ago # #define true 1 #define false 0 int check(int a1[],int a2[],int n1,int n2) { int i; //n1 size of array a1[] and n2 size of a2[] if(n1!=n2) return false; //n1 and n2 must be same for(i=0;ia1[i+1]) && (a2[i]>a2[i+1]) ) ) return false; } return true;//assumed that each array doesn't contain duplicate elements in themshelves }

2720


What is the heap in c?

647


If the size of int data type is two bytes, what is the range of signed int data type?

596


How can I write data files which can be read on other machines with different word size, byte order, or floating point formats?

616


Why should I prototype a function?

644


What is the use of bit field?

648


In a header file whether functions are declared or defined?

633


which type of aspect you want from the student.

1704