merry
BAN USER- 0of 0 votes
AnswersWrite a program to reverse a character array "Hello World". Give different test cases(input arrays) to test your code.
- merry in United States for Quality Engineering| Report Duplicate | Flag | PURGE
Salesforce Quality Assurance Engineer Java Testing - 0of 0 votes
AnswersWrite a program to find the smallest number from an array with elements{1,10, -5, 10} Write the test cases for it(Give different input arrays to test ur code)
- merry in United States for Quality Engineering| Report Duplicate | Flag | PURGE
Salesforce Quality Assurance Engineer Java Testing
<pre lang="" line="1" title="CodeMonkey66588" class="run-this">/* The class name doesn't have to be Main, as long as the class is not public. */
class Main
{
public static int findSmallestInt(int[] A){
int smallest = A[0];
for(int i=0;i<A.length;i++){
if(A[i]<smallest){
smallest=A[i];
}
}
return smallest;
}
public static void main (String[] args) {
int[] array= {1,10,-5,-10};
System.out.print(findSmallestInt(array));
}
</pre><pre title="CodeMonkey66588" input="yes">Test Cases
int[] A = {1,10,-5,-10}
int[] A = {0}
int[] A = {1,10,-5,-10,-11}
int[] A = {1,1,1,1,1}
int[] A = {0,0}
int[] A = {}</pre>
<pre lang="" line="1" title="CodeMonkey93998" class="run-this">/* The class name doesn't have to be Main, as long as the class is not public. */
class Main
{
private static String reverse(String s) {
char temp;
int l = s.length();
char[] a = s.toCharArray();
for(int i =0;i<a.length/2;i++){
temp=a[i];
a[i]=a[l-i-1];
a[l-i-1]=temp;
}
return new String(a);
}
Output: dlroW olleH
public static void main (String[] args) throws java.lang.Exception
{
String str="Hello World"
System.out.print(reverse(str));
}
}
</pre><pre title="CodeMonkey93998" input="yes">
String str="Hello World"</pre>
I want to know how should I handle the case int[] A={}
- merry September 21, 2011should I add try/catch block? or return 0 if(A.length==0)
but 0 is not the right ans