![bfgnnnbddf6830](/avatars/3843.jpg)
bfgnnnbddf6830
20.09.2020 •
Computers and Technology
Write a program that performs the following tasks: Display a friendly greeting to the user Prompt the user for the value to convert (a String) Accept that String Prompt the user for the value of the initial base (an integer) Accept that integer Prompt the user for the desired base of the output (an integer) Accept that integer If the String is not a legal expression of a number in the initial base, display an error message and exit the program. Convert the value represented by the String in the initial base to the desired base. Display the result.
Solved
Show answers
More tips
- H Health and Medicine How to Help Men Gain Weight?...
- A Auto and Moto Discovering the Leader: What is the Most Expensive Car in the World?...
- H Health and Medicine Hangover: How to Get Rid of It Quickly?...
- S Style and Beauty How to Choose the Right Fur Coat and Avoid Regrets?...
- C Computers and Internet How to Create a Folder on Your iPhone?...
- G Goods and services How to sew a ribbon: Tips for beginners...
- F Food and Cooking How to Make Mayonnaise at Home? Secrets of Homemade Mayonnaise...
- C Computers and Internet Which Phone is Best for Internet Surfing?...
- F Food and Cooking Everything You Need to Know About Pasta...
- C Computers and Internet How to Choose a Monitor?...
Answers on questions: Computers and Technology
- C Computers and Technology The effect of technology advancement on a product s life cycle is to a. guarantee long-term viability of the product before it becomes obsolete. b. bring a product...
- C Computers and Technology The radix sort a. treats array entries asif they were strings that have same length b. is not suitable as a general purpose sorting algorithm c.restrcits the data...
- C Computers and Technology When mehtod x calls method y , method y called methhod z, and method z calles method x, this is called a. an error b. mutual recursion c.tail recursion d.indirect...
- C Computers and Technology Which statement best explains the relationship between satelitte technology and the internet...
- C Computers and Technology Factors that can affect a computers performance when outdated...
- C Computers and Technology Which of the following statements about personality are true? check all of the boxes that apply....
- E English Looking for ways to improve the company you work for is an example of:...
- H History Put the following events in the order they occurred: • thomas paine’s african slavery in america article published • medgar evers murdered • naacp founded by w.e.b....
- M Mathematics If 4n = 3.60, which is the value of n? (it s probably a simple question, but i can t decide between 0.9 and 9, if you can me, ! ) a. 0.09 b. 0.9 c. 9 d. 90...
- M Mathematics Make a table of ordered pairs for the equation. y= 1/2x − 3 then plot two points to graph the equation....
Ответ:
Explanation:
import java.util.Scanner;
import java.math.BigInteger;
public class Main
{
private int x;
public static boolean isValidInteger(String theValue, int theBase)
{
BigInteger number = new BigInteger(theValue,theBase);
if(theValue.equals(number.toString(theBase)))
{
return true;
}
else
return false;
}
public static String convertInteger(String theValue, int initialBase, int finalBase)
{
boolean valid=isValidInteger(theValue,initialBase);
if(valid==true)
{
BigInteger number = new BigInteger(theValue);
return(number.toString(finalBase));
}
else
return("String not in initial base");
}
public static void main(String[] args)
{
System.out.println("Welcome");
String value;
int ibase, dbase;
if(args.length==0)
{
Scanner S = new Scanner(System.in);
System.out.println("Enter Value to be converted :: ");
value = S.nextLine();
System.out.println("Enter initial base :: ");
ibase = S.nextInt();
System.out.println("Enter desired base :: ");
dbase = S.nextInt();
}
else
{
value=args[0];
ibase=Integer.parseInt(args[1]);
dbase=Integer.parseInt(args[2]);
}
System.out.println("Change base "+convertInteger(value,ibase,dbase));
}
}
Output
Ответ:
The answer above is correct ^