zoukankan      html  css  js  c++  java
  • hdu 2051 Bitset (java)

    问题:
    之前做过类似题,但这次仍然不能解决相关问题。


    字符串倒过来输:StringBuffer str=new StringBuffer(s); s=str.reverse().toString()


    Bitset

    Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
    Total Submission(s): 15548    Accepted Submission(s): 11804


    Problem Description
    Give you a number on base ten,you should output it on base two.(0 < n < 1000)
     

    Input
    For each case there is a postive number n on base ten, end of file.
     

    Output
    For each case output a number on base two.
     

    Sample Input
    1 2 3
     

    Sample Output
    1 10 11

    代码:

    import java.util.*;
    
    public class Main{
    	public static void main(String args[]){
    		Scanner cin=new Scanner(System.in);
    		while(cin.hasNext()){
    			int n=cin.nextInt();
    			String s="";			
    			while(n!=0){
    				s=s+(n%2);
    				n=n/2;
    			}
    			StringBuffer str=new StringBuffer(s); 
    			s=str.reverse().toString();
    			System.out.println(str);
    		}
    	}
    }
    		


  • 相关阅读:
    Vue入门
    吃透SprinngBoot
    SSM整合详解
    Linux查找端口并关闭
    接入腾讯云的OCR识别身份证信息
    IDEA 快捷键《宋红康版》
    Mysql详解
    docker常见命令
    SpringBoot集成Redis
    使用mybatis出现异常
  • 原文地址:https://www.cnblogs.com/mfrbuaa/p/5069855.html
Copyright © 2011-2022 走看看