Hey I am having trouble with loops the problem is as follows;
My program so far gets me to what I need which is the remainders which are the last digits of the 5 digit number inputted, I need a way for java to keep a running sum of all the remainders and then I need a new variable which is the sum of the remainders after going through the loop.
Any help is greatly appreciated.
mport java.util.Scann er;
public class Document1
{
public static void main(String[] args)
{
Scanner keyboard = new Scanner(System. in);
// Obtain initial data from user
System.out.prin t("Enter 5 digit Integer: ");
int n = keyboard.nextIn t();
getRemainder(n) ;
System.out.prin tln();
}
public static void getRemainder(in t n)
{
for (int i = 1; i < 6; i++)
{
int remainders = n % 10;
n = n / 10;
System.out.prin tln(remainders) ;
System.out.prin tln(n);
System.out.prin tln(" ");
}
int a = n;
System.out.prin tln(a);
My program so far gets me to what I need which is the remainders which are the last digits of the 5 digit number inputted, I need a way for java to keep a running sum of all the remainders and then I need a new variable which is the sum of the remainders after going through the loop.
Any help is greatly appreciated.
mport java.util.Scann er;
public class Document1
{
public static void main(String[] args)
{
Scanner keyboard = new Scanner(System. in);
// Obtain initial data from user
System.out.prin t("Enter 5 digit Integer: ");
int n = keyboard.nextIn t();
getRemainder(n) ;
System.out.prin tln();
}
public static void getRemainder(in t n)
{
for (int i = 1; i < 6; i++)
{
int remainders = n % 10;
n = n / 10;
System.out.prin tln(remainders) ;
System.out.prin tln(n);
System.out.prin tln(" ");
}
int a = n;
System.out.prin tln(a);
Comment