久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

java中以10為底到2、8、16的轉換

Base 10 to base 2,8,16 conversion in java(java中以10為底到2、8、16的轉換)
本文介紹了java中以10為底到2、8、16的轉換的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我在這個面向對象的課程中,但我只是不知道該怎么做.我知道基本的基礎知識,但沒有這樣的.我被要求創建一個程序,將 # 的基數 10 轉換為基數 2、基數 8 和基數 16.然后,在我們被要求將其從 2、8、16 轉換回基數 10 之后.我收集了一些信息來自其他網站,實際上我最終編輯了一些.請幫忙!如果你們真的幫助和編輯自己并將其發送給我,我會更喜歡它,但如果這要求太多,請嘗試指導我完成它,因為我不太了解 Java.到目前為止,我有:

I'm in this Object Oriented class, but I just don't know how to do this. I know basic fundamentals but nothing like this. I am asked to create a program that converts #'s base 10 to base 2, base 8,and base 16. Then, after we are asked to convert it back from 2,8,16 to base 10. I have gathered some information from other websites and I actually ended up editing a bit of it. Please help! I would prefer it if you guys actually helped and edited yourselves and sent it to me, but if that is too much to ask, please try to guide me through it as I do not know much of Java. So far I have:

import java.util.Scanner;

public class baseconverterr
{

public static void main(String[] args) {

      // Read the conversion choice from the user

      System.out.println("Choose 1 or 2 or 3:");

      System.out.println("1: conversion from base 10 to base 2 ");

      System.out.println("2: conversion from base 10 to base 8");

      System.out.println("3: conversion from base 10 to base 16");
      // do you want 1, 2 , or 3? you have your choice
      Scanner in = new Scanner(System.in);

      int choice = in.nextInt();

      String string = in.nextLine();

      // Read in the number to be converted and do the conversion

      String output= "";

      System.out.println("Please enter the number to be converted:");

      int input = in.nextInt();

      if (choice == 1)
      // if the user chooses choice #1, it will convert from base 10 to base 2
          output = Integer.toString(input, 2);

      else if (choice == 2)

          output = Integer.toString(input, 8);

    // if the user chooses choice #2, it will convert from base 10 to base of 8 
     else if (choice == 3)

          output = Integer.toString(input, 16);
   // if the user chooses choice #3, it will convert from base 10 to base 16
  else

      System.out.println("invalid entry");
      // everything else, it is invalid
      System.out.println("final output=" + output);
      // this prints the final output.

推薦答案

對于十進制 x(以 10 為底)可以分別用于二進制、八進制、十六進制轉換

for a decimal x (base 10) you can use respectively for binary, octal, hex conversion

Integer.toString(x, 2),

Integer.toString(x, 8)

Integer.toString(x, 16).

然后將其轉回十進制,分別由二進制、八進制、十六進制轉換

then to convert it back to decimal, respectively from binary, octal, hex conversion

Integer.valueOf(binary_value, 2)

Integer.valueOf(octal_value, 8)

Integer.valueOf(hex_value, 16)

在您的代碼中,更改以下內容:

in your code, change the following:

output = Integer.toString(input, 16) //replace 16 for hex, 8 for octal, 2 for binary 

這篇關于java中以10為底到2、8、16的轉換的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

How to wrap text around components in a JTextPane?(如何在 JTextPane 中的組件周圍環繞文本?)
MyBatis, how to get the auto generated key of an insert? [MySql](MyBatis,如何獲取插入的自動生成密鑰?[MySql])
Inserting to Oracle Nested Table in Java(在 Java 中插入 Oracle 嵌套表)
Java: How to insert CLOB into oracle database(Java:如何將 CLOB 插入 oracle 數據庫)
Why does Spring-data-jdbc not save my Car object?(為什么 Spring-data-jdbc 不保存我的 Car 對象?)
Use threading to process file chunk by chunk(使用線程逐塊處理文件)
主站蜘蛛池模板: 亚洲视频中文字幕 | 久久99深爱久久99精品 | 日韩在线播放视频 | 亚洲欧美精品 | 国产精品成人一区二区 | 在线观看国产 | 国产精品一区二区视频 | 激情毛片| 天天操狠狠操 | 精品国产精品三级精品av网址 | 亚洲电影一区 | japan25hdxxxx日本 做a的各种视频 | 色av一区| 日韩一区二区三区在线视频 | 中国一级特黄真人毛片免费观看 | 日韩视频在线播放 | 91亚洲精品久久久电影 | 久久亚洲国产精品日日av夜夜 | 亚洲精品乱码久久久久久黑人 | 国产91视频免费 | 成人小视频在线观看 | 久久久久久亚洲精品 | 亚洲视频一区二区三区 | 日日夜夜影院 | 91精品国产综合久久婷婷香蕉 | 中文字幕在线观看一区二区 | 成人a视频在线观看 | 国产成人精品免费视频大全最热 | 日本电影韩国电影免费观看 | 国产成人精品一区 | 久久精彩 | 成人一区二区视频 | 天天干视频 | 国产网站在线播放 | 欧美视频网 | 在线黄色影院 | 国产蜜臀| 成年人在线观看视频 | 中文字幕亚洲一区二区va在线 | 国产精品日韩欧美一区二区 | 91久久久久久 |