63 088
Assignments Done
99,1%
Successfully Done
In July 2018

Answer to Question #58912 in Java | JSP | JSF for Sherlynn

Question #58912
//write a method to receive two integer numbers and print the number which is nearer or equal to 20 if both number are more than 20, the method will print 0
public static void main (String [] argv)
{
nearer20 (10, 20); // Output : 20
nearer20 (18, 10); // Output : 18
nearer20 (10, 21); // Output : 10
nearer20 (30, 25); // Output : 0
}
public static void nearer20 (int n1, int n2)
{
continue

//write a method to received two integer arrays and copy the numbers in the first array repeatedly into second array
public static void main (String [] argv)
{
int []sample1 = {1, 2, 3};
int []sample2 = new int [7];
repeatCopy(sample1, sample2);
//sample2 will contain: 1 2 3 1 2 3 1
}
public static void repeatCopy (int [] data1, int[] data2)
Continue
Expert's answer

public class First {

public static void main(String[] argv) {
nearer20(10, 20); // Output : 20
nearer20(18, 10); // Output : 18
nearer20(10, 21); // Output : 10
nearer20(30, 25); // Output : 0
}

public static void nearer20(int n1, int n2) {
String outLine = "";
if(n1>20&&n2>20) outLine += 0;
else if(n1>20 && n2<=20) outLine += n2;
else if(n1<=20 && n2>20) outLine += n1;
else outLine += ((20-n1)<=(20-n2))?n1:n2;
System.out.println(outLine);
}
}



public class Second {

public static void main(String[] argv) {
int[] sample1 = {1, 2, 3};
int[] sample2 = new int[7];
repeatCopy(sample1, sample2);
//sample2 will contain: 1 2 3 1 2 3 1

}

public static void repeatCopy(int[] data1, int[] data2){
for(int i = 0; i < data2.length; i++)
data2[i] = data1[i%data1.length];
}

}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be first!

Leave a comment

Ask Your question

Submit
Privacy policy Terms and Conditions