Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a program in response to the following prompt:Write a method, reverseDigit

ID: 655077 • Letter: W

Question

Write a program in response to the following prompt:Write a method, reverseDigit, that takes an integer as a parameter and returns the number with its digits reversed. For example, the value of reverseDigit(12345) is 54321. Also, write a program to test your method. I have an error I can't figure out.

import java.util.Scanner;
public class Test_Average
{
int num;
int reverse;
Test_Average()
{
}
int Find_Reverse()
{
System.out.println(" Enter the number to reverse : ");//Ask User to input number to reverse
Scanner in = new Scanner(System.in); //Scanner object created
num = in.nextInt(); //Take input from the user
reverse=0;
while( n != 0 )//loop
{
reverse = reverse * 10;
reverse = reverse + n%10;
n = n/10;
}
System.out.println(" Reverse of entered number is "+reverse);
}
};
// now the tester class : -
  
public class Test_Driver
{
public static void main(String args[])
{
Test_Average t=new Test_Average();//Test object created
char c='y';//default user input = y (i have initialized it to y)
//so that i enter the loop once
//if c is anything other than y , then loop condition will not sattisfy
//and user will never be asked for any input
Scanner s=new Scanner(System.in); //input from user as intager
while(c=='y') //loop
{
t.Find_Reverse();//Find Reverse from test_average
System.out.println(" Again ? (y/n) : "); //output
cin>>c; //Takes users input and saves it into c ((ERROR)) -cin>>c; Syntax error on token ">>", invalid AssignmentOperator
}
}
};

Explanation / Answer

For the above program Test_Average class works perfectly there is no errors

while coming to Test_Diver class

scanner class read input from the user so here you put

c =s.next(); try the below

public class Test_Driver
{
public static void main(String args[])
{
Test_Average t=new Test_Average();//Test object created
char c='y';//default user input = y (i have initialized it to y)
//so that i enter the loop once
//if c is anything other than y , then loop condition will not sattisfy
//and user will never be asked for any input
Scanner s=new Scanner(System.in); //input from user as intager

           c=s.next();
while(c=='y') //loop
{
t.Find_Reverse();//Find Reverse from test_average
System.out.println(" Again ? (y/n) : "); //output
     

           }

         System.out.println(c+" invalid AssignmentOperator");
}
};

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote