首页 > 编程 > Java > 正文

HDU 2051 JAVA

2019-11-06 07:21:23
字体:
来源:转载
供稿:网友

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.*;class Main{ public static void main(String args[]){ Scanner sc=new Scanner(System.in); while(sc.hasNext()){ int N=sc.nextInt(); int R=2; if(N<0){N=-N;System.out.print("-");} int x=N/R;int y=N%R; char chs[]={'0','1'}; int []a=new int [50];int i=0; a[0]=N%R; while(x!=0){ i++; y=x%R; a[i]=y; x=x/R; } int b[]=new int[i+1]; for(int k=0;k<i+1;k++){ // System.out.print(a[k]+" a"); b[k]=a[i-k]; //System.out.print(b[k]+" "); } for(int j=0;j<b.length;j++){ System.out.print(chs[b[j]]); } System.out.println(); } }}
上一篇:HDU 2052 JAVA

下一篇:java面试题

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表