a = ((i * (i + 1)) / 2) + 5;
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 33 from the first i numbers in the series.
How can i multiple number by the previous number in the series?
/** * Created by User on 10/2/2015. */ public class Task55248 { public static void main (String[] args){ BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); boolean err = false; int num=0; do{ try{ err=false; System.out.println("Enter integer value of i: "); num=Integer.parseInt(reader.readLine()); }catch (NumberFormatException e){ System.out.println("Error. Please try again and enter integer value"); err=true; }catch(Exception e){ System.out.println("Error. Program will be closed"); } }while(err);
int a[] = new int[num];
for(int j=0; j<a.length; j++){ int i = j+1; // from i=1 to num a[j]=((i * (i + 1)) / 2) + 5; }
for(int j=a.length-1; j>0; j--){ if(a[j]*a[j-1]%33==0){ System.out.println("Answer is "+a[j-1] + " and "+a[j]); break; int result = a[j]*a[j-1]; } } } }
Comments
Leave a comment