#need help with some code i gotta present today
13 messages · Page 1 of 1 (latest)
⌛ This post has been reserved for your question.
Hey @proper otter! Please use
/closeor theClose Postbutton above when you're finished. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.
TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.
this is the code
package com.example.s2_project_final;
import org.jetbrains.annotations.Contract;
import org.jetbrains.annotations.NotNull;
import java.math.BigInteger;
public class Convert {
// Funksionet e kovertimit
@NotNull
@Contract(pure = true)
public static String doconvert(String inputi, String from, String to) {
int fromBase = getBase(from);
int toBase = getBase(to);
BigInteger number = new BigInteger(inputi, fromBase);
return number.toString(toBase);
}
private static int getBase(String vlerat) {
return switch (vlerat) {
case "Binar" -> 2;
case "Decimal" -> 10;
case "Oktal" -> 8;
case "Heksadecimal" -> 16;
default -> throw new UnsupportedOperationException("Invalid numeral system: " + vlerat);
};
}
}
this is supposed to turn numbers into other types of numbers (decimal numbers to binary, octal, hexadecimal and vise versa)