Ex:1 modulus graups A modulus group for o specaitic numbers theo o num bsrs that
ID: 3593291 • Letter: E
Question
Ex:1 modulus graups A modulus group for o specaitic numbers theo o num bsrs thatn have the Same modulus when d'vided b the specpc number. For in sta n ce 34 mod 69?elds Also 4o mod 6 ytelds 4 50 34 ond 4o bedeng to the Same modulus for 6 . group alrite Pseudocode for a progrom that wil allow the user -to enter a modus rop num ber: Then they witt be asked to enter 5 pace Separated value pe shtive integers whose modolus grouP number will be cevated and eported for the arou Test case:it the user entere] 5 os the modulus roup nom ber and -then enters 56,92,13,7,4 The program would create the fo llowi'n a result The maduus 5 group fos 56 s i,for 92 rs 2, for 13 is 3, for 7 is2 and for 1 1 The user Should be able to process this as a ten as they want without exts ting the Prog ramExplanation / Answer
package com.rebate;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class ModulesNumber {
public static void main(String[] args) throws IOException {
// BufferedReader is a class it allows user to get input from console.
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
// assign one variable to allow multiple modules calculations
String nextMudulesRequried = null;
do {
// Enter the modules number from console
System.out.println("Enter Module Number");
String num = reader.readLine();
System.out.print("Enter Set of Positive Numbers By Space separated: ");
String setOfPositiveNum = reader.readLine();
// spit the given positive numbers by space
// out of this gets list of numbers
String[] lPositiveNumArr = setOfPositiveNum.split(" ");
System.out.print("The Modules for " + num + " group ");
//iterate one by one each positive number from list of positive values
for (String number : lPositiveNumArr) {
// validating number format if entered value contain any negative or empty throw numberformatExecption
if(number!=null && !number.contains("-"))
{
//converting string positive number to integer values
int currentMod = Integer.parseInt(number);
//converting string modules number to integer values
int num1=Integer.parseInt(num);
//finding out the modules group for current positive number
currentMod = currentMod % num1;
//printing out result asper requirment
System.out.print("For "+ number + " is " + currentMod + ", ");
}
else
{
//for readablity perpose using print line
System.out.println();
//throwing number formatexecption
throw new NumberFormatException("Invalid Number Entered For "+ number);
}
}
System.out.println();
//if you want to continue the calculation enter Y or else enter N
System.out.print("Continue(Y/N) ");
//converting to lower case for validating the next iteration
nextMudulesRequried = reader.readLine().toLowerCase();
} while (nextMudulesRequried.equals("y"));
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.