P1:实现两个矩阵之间的加法和维度检查
P2:input手机9键对应output数字
switch-case用法:当多个条件对应一种情况时:
case 'a': case 'b': case 'c': list.add(2); break;
补:switch-case语句中,default语句的位置不受影响(始终最后判断)
P3:判断一个整数是否是2的整数幂
public static boolean isPowerOfTwo(int n) { if (n==0) return false; for (;;){ if (n%2==0) n /= 2; else{ if (n==1) return true; return false; } } }
P4:将一个整数中的数字进行颠倒
Integer中的方法:
二进制的reverse:
Integer.toString(n);
intValue():
/** * Returns the value of this {@code Integer} as an * {@code int}. */ public int intValue() { return value; }//
/** * The value of the {@code Integer}. * * @serial */ private final int value;
---------------------------------------------------------------
主方法:直接return(n为传入的int)
在之前要判断正负
Integer.valueOf(new StringBuffer(Integer.toString(n)).reverse().toString()).intValue()
P5:字符串翻转
传入String s
return new StringBuffer(s).reverse().toString();
============================================================================
String & int 互相转换:
String to int
1). int i = Integer.parseInt([String]);
或 i = Integer.parseInt([String],[int radix]);
//radix为进制
2). int i = Integer.valueOf(my_str).intValue()
int to String
1.) String s = String.valueOf(i);
2.) String s = Integer.toString(i);
3.) String s = "" + i。