当运算出现int或int右边的变量类型时,自动升级为运算中最右边的类型.byte->short->int->long->float->double
char->int->long->float->double
明白了一些概念问题:\r是将光标移到开始, \n是将光标移到下一行,\b是将光标向前移动一个字符
再分享一个菱形程序:
package homework1_9;
public class HomeWork5 {
static char c='*';
public static void main(String[] args) {
// TODO Auto-generated method stub
int length=4;
for(int i=length-1; i>-length; i--)
{
printChar(Math.abs(i)+1);
if(Math.abs(i)==length-1)
{
System.out.println();
continue;
}
printChar(2*(length-Math.abs(i)-1));
System.out.println();
}
}
public static void printChar(int position)
{
for(int i=1; i<position; i++)System.out.print(' ');
System.out.print(c);
}
}
|
|