Question

Java program Lab Description:Convert a base ten number to any provided base Lab Goal : This...

Java program

Lab Description:Convert a base ten number to any provided base

Lab Goal : This lab was designed to teach you how to use while and do while loops

0 0
Add a comment Improve this question Transcribed image text
Answer #1
import java.util.Scanner;

public class ConvertToAnyBase {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        System.out.print("Enter a number to convert: ");
        int n = in.nextInt();
        System.out.print("Enter base value: ");
        int base = in.nextInt();
        String result = "";
        while (n > 0) {
            result = (n % base) + result;
            n /= base;
        }
        System.out.println(result);
    }
}
Add a comment
Know the answer?
Add Answer to:
Java program Lab Description:Convert a base ten number to any provided base Lab Goal : This...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Lab Goal :   This lab was designed to teach you how to use while and do...

    Lab Goal :   This lab was designed to teach you how to use while and do while loops. Lab Description :   A perfect number is any number that is equal to the sum of its divisors. 6 is perfect because it has divisors 1, 2, and 3 which sum to 6.   Determine if the provided numbers are perfect. Use mod (%) to find divisors. Files Needed :: Perfect.java PerfectRunner.java Sample Data : 496 45 6 14 8128 1245 33 28...

  • Lab Goal : The lab was designed to teach you more about objects and classes. Lab...

    Lab Goal : The lab was designed to teach you more about objects and classes. Lab Description : In this program, you are to create a Roman Numeral class to handle roman numeral operations. How to convert a Roman Numeral to a standard base ten number : : Locate the first individual roman number in the roman number string. Sum up the numeric value of the individual number. Chop of the individual roman numeral from the string and continue the...

  • IN JAVA Goals The primary goal of this lab is to write, test and complete a...

    IN JAVA Goals The primary goal of this lab is to write, test and complete a program with multiple classes, where you have designed and implemented those classes. You will also code and use methods and at tributes. This program will have an interactive behavior. This will reinforce the need for good design and creating and using new classes. The lab will build a rudimentary chat system to reinforce the concept ofc objects. betweern 1. Design a Person class. 2....

  • .Need code for my java class !! Write a simple java program that uses loops. You...

    .Need code for my java class !! Write a simple java program that uses loops. You may use ‘WHILE’ or ‘FOR’ or ‘DO-WHILE’ – you decide. The program should use a loop to compute the semester average for up to 5 students. In the loop the user will ask for a student name and their 3 test scores and add them up and divide the total by 3 giving the semester average. You will print out the student name and...

  • Java language Any use of java.util.LinkedList is prohibited Objective: The goal of this assignment is to...

    Java language Any use of java.util.LinkedList is prohibited Objective: The goal of this assignment is to practice recursion. ignment: The assignment requires writing recursive methods for some linked list operations. The use of loops in the recursive methods is strictly prohibited in this assignment. That is, you cannot use for, while, and do-while in the recursive methods you will write. You can only use a loop when you will initiate values for a linked list in the main method. You...

  • Write a program that receives a real number in decimal (base 10) and converts it into...

    Write a program that receives a real number in decimal (base 10) and converts it into any base (e.g., 2, 8, 16, 60) You may not use libraries or built-in functions (e.g., Double.toHexString(...) in Java or ”{0:b}”.format(...)in Python) please in python exampe 0.5 convert to 0.1

  • In this lab, you complete a partially written Java program that includes two methods that require...

    In this lab, you complete a partially written Java program that includes two methods that require a single parameter. The program continuously prompts the user for an integer until the user enters 0. The program then passes the value to a method that computes the sum of all the whole numbers from 1 up to and including the entered number. Next, the program passes the value to another method that computes the product of all the whole numbers up to...

  • In this lab, you complete a partially written Java program that includes two methods that require...

    In this lab, you complete a partially written Java program that includes two methods that require a single parameter. The program continuously prompts the user for an integer until the user enters 0. The program then passes the value to a method that computes the sum of all the whole numbers from 1 up to and including the entered number. Next, the program passes the value to another method that computes the product of all the whole numbers up to...

  • Overview: In this lab you are to write a Java program to prompt the user for...

    Overview: In this lab you are to write a Java program to prompt the user for an integer indicating a year and then print the calendar for that year. Objective: This lab's objective is to exercise you with the use of Java’s control statements. You are required to use exactly one while statement, one for statement and one switch statement. You will also practice on how to use some basic input methods of the Scanner class and some formatting techniques...

  • Write a java program that demonstrates recursion. This program can be in a java GUI frame...

    Write a java program that demonstrates recursion. This program can be in a java GUI frame or as a console application. On this one it is up to you. (It would probably work better as a console program for this particular program.) The input for this program is a number of boxes. Ask the user for this with a textbox or a prompt on the command line. Demonstrate recursion with a function called LoadTruck() that takes a number of boxes...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT