60 384
Assignments Done
98,1%
Successfully Done
In April 2018

Answer to Question #57822 in Java | JSP | JSF for Nithya

Question #57822
Write a program that asks the user to input an integer, i, and determines the largest consecutive pair of numbers whose product is divisible by 19 from the first i numbers in the series.
Note: You may need to declare some of variables as long instead of int in order to make sure they can get large enough.
Expert's answer
import java.util.Scanner;

public class Main {

public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("Please enter an integer value: ");
int s = sc.nextInt();
System.out.print("Please enter i: ");
int i = sc.nextInt();
long result = -1;
for (long l = i + s - 1; l >= s; l--) {
if ((l * (l+1)) % 19 == 0) {
result = l;
break;
}
}
if (result == -1) System.out.println("No consecutive pair has been found withing the range");
else System.out.println("The largest consecutive pair whose product is divisible by 19 within the range is: " +
result + ", " + (result+1));
}
}import java.util.Scanner;

public class Main {

public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("Please enter an integer value: ");
int s = sc.nextInt();
System.out.print("Please enter i: ");
int i = sc.nextInt();
long result = -1;
for (long l = i + s - 1; l >= s; l--) {
if ((l * (l+1)) % 19 == 0) {
result = l;
break;
}
}
if (result == -1) System.out.println("No consecutive pair has been found withing the range");
else System.out.println("The largest consecutive pair whose product is divisible by 19 within the range is: " +
result + ", " + (result+1));
}
}

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