Epic Systems Interview Question
Software Engineer / Developers<pre lang="java" line="1" title="CodeMonkey2687" class="run-this">/* The class name doesn't have to be Main, as long as the class is not public. */
class Main
{
public static void main (String[] args) throws java.lang.Exception
{
java.io.BufferedReader r = new java.io.BufferedReader (new java.io.InputStreamReader (System.in));
String s;
while (!(s=r.readLine()).startsWith("42")) System.out.println(s);
}
}
int main( )
{
int nos[25], i=0, a, b, temp;
nos[0]=1;
for(i =0; i<= 25; i++)
{
cout<< "enter and integer: "<< endl;
cin>> nos[i];
if ( nos[i] == 0)
{
break;
}
else
continue;
}
for ( a= 0; a<= i; a++)
{
for(b=0; b<= i; b++)
{
if (nos[b]< nos[b+1])
{
temp = nos[b];
nos[b]= nos[b+1];
nos[b+1] = temp;
}
else
continue;
}
}
cout<< "Largest number entered by user" << nos[0]<<endl;
cout<<"smallest number"<< nos[i]<<endl
;
system("PAUSE");
return 0;
}
</pre><pre title="CodeMonkey2687" input="yes">
</pre>
int main()
{
int maxOdd = 0;
int minEven = 10000000;
string input;
int intVal;
while(true)
{
getline(cin,input);
intVal = atoi(input.c_str());
if(intVal != 0)
{
if(intVal%2 == 0)
{
if(intVal<minEven)
minEven = intVal;
}
else if(intVal>maxOdd)
{
maxOdd = intVal;
}
}
else if(intVal == 0)
{
cout<<"Terminating integer entered or invalid character...press any key to exit\n";
break;
}
}
cout<<"FTW Min Even = "<<minEven<<endl;
cout<<"FTW Max Odd = "<<maxOdd<<endl;
getchar();
}
There is no assumption that the input is set of integers, the above codes should take care of the float point numbers.(Simply ignore such numbers, but it's necessary)
<pre lang="c++" line="1" title="CodeMonkey18158" class="run-this">#include <iostream>
#include <string>
#include <sstream>
#define N 64
using namespace std;
void main(){
int input[N];
cout<<"please input: "<<endl;
int i = 0;
while(cin>>input[i]){
if(input[i]==0) break;
i++;
}
int maxodd=input[0];
int mineven=input[i-1];
for(int k = 0; k <i-1;k++){
if(input[k]>maxodd&&input[k]%2==1) maxodd=input[k];
if(input[k]<mineven&&input[k]%2==0) mineven=input[k];
}
cout<<"max odd is: "<<maxodd<<" and min even is: "<<mineven<<endl;
system("pause");
}
</pre><pre title="CodeMonkey18158" input="yes">
</pre>
public static void main(String[] args) throws IOException
{
print("Enter a number");
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int i=0, min_even=Integer.MAX_VALUE, max_odd=Integer.MIN_VALUE;
while(true)
{
i = Integer.parseInt(br.readLine());
if(i==0)
break;
if(i%2 == 0)
{
if(i < min_even)
min_even = i;
}
else
{
if(i > max_odd)
max_odd = i;
}
}
print("The min even is: " + Integer.toString(min_even));
print("The max odd is: " + Integer.toString(max_odd));
}
public static void main(String[] args) throws IOException
- Anonymous November 19, 2010{
print("Enter a number");
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int i=0, min_even=Integer.MAX_VALUE, max_odd=Integer.MIN_VALUE;
while(true)
{
i = Integer.parseInt(br.readLine());
if(i==0)
break;
if(i%2 == 0)
{
if(i < min_even)
min_even = i;
}
else
{
if(i > max_odd)
max_odd = i;
}
}
print("The min even is: " + Integer.toString(min_even));
print("The max odd is: " + Integer.toString(max_odd));
}