Java Question help Base four
import java.util.Scanner;_x000D_
_x000D_
public class BaseFour{_x000D_
_x000D_
public static void main(String[] args){_x000D_
_x000D_
Scanner scan = new Scanner(System.in);_x000D_
String input = "";_x000D_
_x000D_
// So long as the String input is NOT 1-60 in length,_x000D_
// Ask the user to enter a valid base-4 number up to 60 digits_x000D_
// Save the next line of user input to the variable "input"_x000D_
_x000D_
_x000D_
// If the input string is NOT base-4, tell the user "Bad input!"_x000D_
// Otherwise, tell the user "You entered [numeric value of input]"_x000D_
// You can call the methods like so:_x000D_
// isBaseFour(input) This will give you a true or false value_x000D_
// baseFourValue(input) This will give you a long value_x000D_
_x000D_
}_x000D_
_x000D_
private static boolean isBaseFour(String input){_x000D_
_x000D_
_x000D_
// Go over each character of input_x000D_
// If that single character is NOT '0' or'1' or '2' or '3', return false immediately_x000D_
// If you finish going through the characters, return true_x000D_
return true;_x000D_
}_x000D_
_x000D_
private static long baseFourValue(String input){_x000D_
long result;_x000D_
_x000D_
// To start, the exponent is 0 and the next position in _x000D_
// in the input string is the string length minus one. _x000D_
// You already have a long variable to hold your result._x000D_
// While the exponent is smaller than the string length, _x000D_
// Get the character at the next position in the input string_x000D_
// and store it in a char variable_x000D_
// Subtract '0' (not 0) from that character and multiply _x000D_
// the result of that subtraction by (long) Math.pow(4, exponent)_x000D_
// When the loop is finished, assign the result to the variable "result"_x000D_
_x000D_
return result;_x000D_
}_x000D_
_x000D_
}_x000D_
You will need to do the following things:
- Get a String of input from the user.
- Depending on whether the input is valid, announce the number’s value; otherwise, let the user know it is bad input.
- Write a method to verify whether or not the user’s input string is valid.
- Write a method to calculate the value of the user’s input string.
"You need a similar assignment done from scratch? Our qualified writers will help you with a guaranteed AI-free & plagiarism-free A+ quality paper, Confidentiality, Timely delivery & Livechat/phone Support.
Discount Code: CIPD30
Click ORDER NOW..


