Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- public class Main {
- public static void main(String[] args) {
- Scanner in = new Scanner(System.in);
- in.useLocale(Locale.US);
- long number, choice, wahl;
- String convert;
- byte ByteSize = 8, ShortSize = 16, IntSize = 32, LongSize = 64, FloatSize = 32, DoubleSize = 64;
- System.out.println("Введите число для конвертации:");
- number = in.nextLong();
- System.out.println("Выберите куда конвертировать \n 1 - двоичный формат числа \n 2 - Восьмиричная форма \n 3 - Шеснадцатиричная форма");
- choice = in.nextLong();
- if (choice == 1) {
- convert = Long.toBinaryString(number);
- if (convert.length() < 8) {
- System.out.println("куда конвертировать? \n 1 - Byte \n 2 - Short \n 3 - Int \n 4 - Long \n 5 - Float \n 6 - Double ");
- wahl = in.nextLong();
- if (wahl == 1) {
- for (int i= convert.length(); i != ByteSize; i++)
- { System.out.print("0"); } System.out.println(convert); }
- else if (wahl == 2) {
- for (int i= convert.length(); i != ShortSize; i++)
- { System.out.print("0"); } System.out.println(convert); }
- else if (wahl == 3) {
- for (int i= convert.length(); i != IntSize; i++)
- { System.out.print("0"); } System.out.println(convert); }
- else if (wahl == 4) {
- for (int i= convert.length(); i != LongSize; i++)
- { System.out.print("0"); } System.out.println(convert); }
- else if (wahl == 5) {
- for (int i= convert.length(); i != FloatSize; i++)
- { System.out.print("0"); }
- Float parse = Float.parseFloat(convert); System.out.println(parse); }
- else if (wahl == 6) {
- for (int i= convert.length(); i != DoubleSize; i++)
- { System.out.print("0"); } Double parse = Double.parseDouble(convert); System.out.println(parse); }
- else {System.out.println("Пожалуйста, введите корректные данные"); }
- return; }
- if (convert.length() < 16) {
- System.out.println("куда конвертировать? \n 1 - Short \n 2 - Int \n 3 - Long \n 4 - Float \n 5 - Double ");
- wahl = in.nextLong();
- if (wahl == 1) {
- for (int i= convert.length(); i != ShortSize; i++)
- { System.out.print("0"); } System.out.println(convert); }
- else if (wahl == 2) {
- for (int i= convert.length(); i != IntSize; i++)
- { System.out.print("0"); } System.out.println(convert); }
- else if (wahl == 3) {
- for (int i= convert.length(); i != LongSize; i++)
- { System.out.print("0"); } System.out.println(convert); }
- else if (wahl == 4) {
- // for (int i= convert.length(); i != FloatSize; i++)
- // { System.out.print("0"); }
- Float parse = Float.parseFloat(convert); System.out.println(parse); }
- else if (wahl == 5) {
- for (int i= convert.length(); i != DoubleSize; i++)
- { System.out.print("0"); } Double parse = Double.parseDouble(convert); System.out.println(parse); }
- else {System.out.println("Пожалуйста, введите корректные данные"); }
- return; }
- if (convert.length() < 32) {
- System.out.println("куда конвертировать? \n 1 - Int \n 2 - Long \n 3 - Float \n 4 - Double ");
- wahl = in.nextLong();
- if (wahl == 1) {
- for (int i= convert.length(); i != IntSize; i++)
- { System.out.print("0"); } System.out.println(convert); }
- else if (wahl == 2) {
- for (int i= convert.length(); i != LongSize; i++)
- { System.out.print("0"); } System.out.println(convert); }
- else if (wahl == 3) {
- for (int i= convert.length(); i != FloatSize; i++)
- { System.out.print("0"); } Float parse = Float.parseFloat(convert); System.out.println(parse); }
- else if (wahl == 4) {
- for (int i= convert.length(); i != DoubleSize; i++)
- { System.out.print("0"); } Double parse = Double.parseDouble(convert); System.out.println(parse); }
- else {System.out.println("Пожалуйста, введите корректные данные"); }
- return; }
- if (convert.length() < 64) {
- System.out.println("куда конвертировать? \n 1 - Long \n 2 - Double ");
- wahl = in.nextLong();
- if (wahl == 1) {
- for (int i= convert.length(); i != LongSize; i++)
- { System.out.print("0"); } System.out.println(convert); }
- else if (wahl == 2) {
- for (int i= convert.length(); i != DoubleSize; i++)
- { System.out.print("0"); } Double parse = Double.parseDouble(convert); System.out.println(parse); }
- else {System.out.println("Пожалуйста, введите корректные данные"); }
- return; }
- convert = Long.toOctalString(number);
- System.out.println(convert); }
- else if (choice == 2)
- { convert = Long.toOctalString(number); System.out.println(convert); }
- else if (choice == 3)
- { convert = Long.toHexString(number); System.out.println(convert); }
- else {System.out.println("Пожалуйста, введите корректные данные"); }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement