Skip to content

Instantly share code, notes, and snippets.

@DominicFinn
Created October 9, 2012 10:49
Show Gist options
  • Save DominicFinn/3857922 to your computer and use it in GitHub Desktop.
Save DominicFinn/3857922 to your computer and use it in GitHub Desktop.
Marks Code
import java.util.Scanner;
class cs210L3
{
public static void main(String[] args)
{
Scanner input = new Scanner(System.in);
//prompt me for a number
System.out.println("pick a number");
//input vairbale
int numberIn = input.nextInt();
//prompt me for a number
System.out.println("\nnow pick a base");
//input base variable
int base = input.nextInt();
System.out.print("\n" + numberIn + " to the base " + base + " = "); //print
while (numberIn > 0)
{
int remainder = numberIn % base;
char charRemainder = ' ';
if (remainder <= 9)
{
//System.out.print(remainder);
numberIn = numberIn / base;
}
else if(remainder > 9)
{
int i = remainder + 55;
charRemainder = (char) i;
//System.out.print(charRemainder);
numberIn = numberIn / base;
}
String strRemainder;
if(charRemainder == ' ') {
strRemainder = " " + remainder;
} else {
strRemainder= " " + remainder + charRemainder;
}
for (int i = strRemainder.length(); i >= 0; i--)
{
System.out.print(strRemainder.charAt(i));
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment