1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
guapka [62]
2 years ago
13

Write a program that performs the following tasks: Display a friendly greeting to the user Prompt the user for the value to conv

ert (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.
Computers and Technology
1 answer:
andrezito [222]2 years ago
3 0

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

You might be interested in
What are the four conditions to help determine whether a website is a good source for information?
Ratling [72]

Answer:

1. Credible Websites are Registered with Legitimate Institutions 2. Watch out for Dummy Content for Website Credibility Check 3. Watch out for Scam Advertisements to Verify Website Credibility 4. Professional Designs Mean Everything

Explanation:

3 0
1 year ago
What is the Windows command to see the IP configuration of the PC?
lisov135 [29]
The answer is ipconfig
4 0
3 years ago
Substance abuse is an _____ coping mechanism.
hichkok12 [17]
Mental coping mechanism.
7 0
2 years ago
Who go to Tennessee Connection Academy And If yall Do plz comment down below.
zalisa [80]

Answer:

it a or d

Explanation:

7 0
2 years ago
"Write an iterative function iterPower(base, exp) that calculates the exponential baseexp by simply using successive multiplicat
sp2606 [1]

Answer:

I am writing the function using Python. Let me know if you want the program in some other programming language.            

def iterPower(base, exp):    

    baseexp = 1

    while exp > 0:

        baseexp = baseexp*base

        exp= exp - 1

    return baseexp

base = 3

exp = 2

print(iterPower(base, exp))

Explanation:

  • The function name is iterPower which takes two parameters base and exp. base variable here is the number which is being multiplied and this number is multiplied exponential times which is specified in exp variable.
  • baseexp is a variable that stores the result and then returns the result of successive multiplication.
  • while loop body keeps executing until the value of exp is greater than 0. So it will keep doing successive multiplication of the base, exp times until value of exp becomes 0.
  • The baseexp keeps storing the multiplication of the base and exp keeps decrements by 1 at each iteration until it becomes 0 which will break the loop and the result of successive multiplication stored in baseexp will be displayed in the output.
  • Here we gave the value of 3 to base and 2 to exp and then print(iterPower(base, exp)) statement calls the iterPower function which calculates the exponential of these given values.
  • Lets see how each iteration works:
  • 1st iteration

baseexp = 1

exp>0 True because exp=2 which is greater than 0

baseexp = baseexp*base

               = 1*3 = 3

So baseexp = 3

exp = exp - 1

      = 2 - 1 = 1    

exp = 1

  • 2nd iteration

baseexp = 3

exp>0 True because exp=1 which is greater than 0

baseexp = baseexp*base

               = 3*3 = 9

So baseexp = 9

exp = exp - 1

      = 1-1 = 0    

exp = 0

  • Here the loop will break now when it reaches third iteration because value of exp is 0 and the loop condition evaluates to false now.
  • return baseexp statement will return the value stored in baseexp which is 9
  • So the output of the above program is 9.
5 0
2 years ago
Other questions:
  • When you sort a cell range using a to z or z to a, what is rearranged?
    5·1 answer
  • What computer system was the first to run the unix operating system?
    11·1 answer
  • A ________ -tier design includes a middle layer between the client and server that processes the client requests and translates
    11·1 answer
  • Given an array of n distinct integers,d = [d[0], d[1],.., d[n - 1]], and an integer threshold, t, how many (a,b,c) index triplet
    11·1 answer
  • Interactive sites where users write about personal topic and comment to threaded discussion are called?
    10·2 answers
  • An insurance company utilizes SAP HANA for its day-to-day ERP operations. Since they can’t migrate this database due to customer
    5·1 answer
  • Write a recursive function that returns 1 if an array of size n is in sorted order and 0 otherwise. Note: If array a stores 3, 6
    13·1 answer
  • What statement best describes entrepreneurship?
    7·2 answers
  • Sara wants to set up her lights to turn on when she arrives home. She has heard that she might be able to do this using IoT. Wha
    12·2 answers
  • Can someone help me debug this please
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!