标签:style blog ar color os sp java on div
描述现在给你一个16进制的加减法的表达式,要求用8进制输出表达式的结果。
3
29+4823
18be+6784
4ae1-3d6c
44114
100102
6565
1 import java.util.Scanner; 2 3 public class Main { 4 public static void main(String[] args) { 5 Scanner scanner=new Scanner(System.in); 6 int T; 7 String s; 8 int number1; 9 int number2; 10 int sum; 11 String sumString; 12 String words[]; 13 String regex; 14 15 T=scanner.nextInt(); 16 17 while(true){ 18 if(T==0) 19 break; 20 T--; 21 22 s=scanner.next(); 23 24 if(s.contains("+")){ 25 regex="[+]"; 26 } 27 else 28 regex="[-]"; 29 30 words=s.split(regex); 31 number1=Integer.parseInt(words[0], 16); 32 number2=Integer.parseInt(words[1],16); 33 34 if(s.contains("+")){ 35 sum=number1+number2; 36 } 37 else 38 sum=number1-number2; 39 40 sumString=Long.toOctalString(sum); 41 System.out.println(sumString); 42 } 43 } 44 }
标签:style blog ar color os sp java on div
原文地址:http://www.cnblogs.com/zqxLonely/p/4132397.html