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
In a "block" containment strategy, in which the attacker's path into the environment is disrupted, you should use the most preci
Slav-nsk [51]
The containment strategy prevents intruders from removing information assets from the network, and prevents attackers from using the organization's network as a launch point for subsequent attacks.
In a "block" containment strategy, in which the attacker's path into the environment is disrupted, you should use the most precise strategy possible, starting with <span>blocking a specific IP address. Correct answer: C

</span>

8 0
3 years ago
Ethan is responsible for writing the dialogue in a movie. Which role is he playing? Ethan is playing the role of a(n).....''BLAN
iVinArrow [24]
Screenwriter! A screenwriter's role is to pen the script for a film.
3 0
3 years ago
Font changes can only be applied on a word-by-word basis.<br><br><br> A.True<br><br><br> B.False
Sergio039 [100]
B. False, it doesnt only have to be applied word by word


3 0
3 years ago
Read 2 more answers
Why is Thomas Jefferson considered an accomplished man , or a Renaissance man?​
lesantik [10]
The term “Renaissance man” means for a very clever person to be good at many different things.
4 0
3 years ago
Write a method starString that accepts an integer parameter n and returns a string of stars (asterisks) 2n long (i.e., 2 to the
lys-0071 [83]

Answer:

public class Main

{

public static void main(String[] args) {

 System.out.println(starString(4));

}

public static String starString(int n){

    double p = Math.pow(2,n);

    String s = "";

    for(int i=0; i<p; i++)

        s += "*";

       

   return s;

}

}

Explanation:

Create a method named starString that takes an integer parameter, n

Get the 2 to the nth power using pow method and set it to the p

Create an empty string that will hold the asterisks

Create a for loop that will iterate p times. Inside the loop, concatenate an asterisk to the s

Return the s

Inside the main method, call the method with an integer parameter

4 0
3 years ago
Other questions:
  • Jesse is writing a physics quiz about the motion of a roller coaster cart. He has a clip art illustration of a cart rolling hori
    9·2 answers
  • A url consists of a ____, a domain name, sometimes the path to a specific web page or location in a web page, and the web page n
    11·1 answer
  • Which of the following is LEAST needed when programming a computer?
    7·1 answer
  • Pls help! ive been looking everywhere online but I couldn't find the answer to this:
    5·1 answer
  • A strategy to solve a logic problem is to break it into steps. Using the drop-down menu, complete these sentences about solving
    15·2 answers
  • The algorithm credited to Euclid for easily finding the greatest common divisor of two integers has broad significance in crypto
    11·1 answer
  • which three objects can be linked or embedded in a word document? A. worksheets, margins, colors B. charts, worksheets, images C
    7·1 answer
  • Suppose that a computer has three types of floating point operations: add, multiply, and divide. By performing optimizations to
    7·1 answer
  • Write a program. in QBAsSIC
    13·1 answer
  • Budgeting for a Computer
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!