import java.util.Scanner;
public class cloveless_Octal
{
public static void main ( String args[] )
{
int x, o1, o2, o3, o4, o5;
Scanner in = new Scanner ( System.in );
System.out.print ( "Please enter a number between 0 and 32767 to convert:" );
x = in.nextInt();
o1 = x/8^5;
o2 = x/8^4;
o3 = x/8^3;
o4 = x/8^2;
o5 = x/8^1;
System.out.printf ( "Your integer " + x );
System.out.printf ( " is " +o5, o4, o3, o2, o1 );
System.out.printf ( " in octal." );
}}
I am not sure what is going wrong. As of right now, I can compile the program, but if I were to enter "15" as the input , the program tells me that the octal equivalent is "0".
I am very new to Java and this is for an assignment. We must use the "/" and "%" operators and I know I am missing something, but I am not sure where to go from here. All I really need is a point in the right direction and I should be able to go from there.
Thank you!
P.S. Could someone explain what modulus "%" does?

New Topic/Question
Reply




MultiQuote




|