Hey guys, I hope somebody can help. I'm writing a program to reverse a number, and I'm getting an error code and can't figure out why. Hope someone can help. Thanks
import java.util.*;
class Assign4B
{
public static void main(String[]args)
{
int number;
int x;
int reversenumber;
Scanner input = new Scanner(System. in);
System.out.prin tln("Please type a four-digit number for x");
number = input.nextInt() ;
number = x;
int ones;
int tens;
int hundreds;
int thousands;
thousands = x / 1000;
x -= thousands * 1000;
hundreds = x / 100;
x -= hundreds * 100;
tens = x / 10;
x -= tens * 10;
ones = x;
x = ones*1000 + tens*100 + hundreds*10 + thousands;
System.out.prin tf("Reverse:%8. 2f",x);
}
}
out:variable x has not been initialized??
import java.util.*;
class Assign4B
{
public static void main(String[]args)
{
int number;
int x;
int reversenumber;
Scanner input = new Scanner(System. in);
System.out.prin tln("Please type a four-digit number for x");
number = input.nextInt() ;
number = x;
int ones;
int tens;
int hundreds;
int thousands;
thousands = x / 1000;
x -= thousands * 1000;
hundreds = x / 100;
x -= hundreds * 100;
tens = x / 10;
x -= tens * 10;
ones = x;
x = ones*1000 + tens*100 + hundreds*10 + thousands;
System.out.prin tf("Reverse:%8. 2f",x);
}
}
out:variable x has not been initialized??
Comment