/*这是一个用“*”打印任意菱形的程序 但是通过rows=System.in.read() 来接受输入的时候 我是用rows=rows-48;结果只能接受1-9的数字 请高手指点 还有什么好的方法阿 摆脱阿
*/
import java.io.*;
public class J_square
{
static int rows;
static int half;
static int sum;
J_square() throws Exception
{
System.out.print("请输入您要输出的菱形的行数:");
rows=InputStream.read();
rows=rows-48;
if(rows%2==0)
{
System.out.println("请输入奇数!");
rows=0;
System.exit(-1);
}
half=rows/2;
sum=rows*2-2;
} public static void main(String args[]) throws Exception
{
J_square f=new J_square();
int i=0,j,k;
System.out.println(f.rows);
for(;i<f.rows;i++)
{
if(i<=f.half)
{
for(j=0;j<f.half-i;j++)
{
System.out.print(" ");
}
for(k=0;k<2*i;k++)
{
System.out.print("*");
if(i==f.half&&k==f.half) System.out.print("\b+");
}
System.out.println("*");
} else
{
for(j=f.half;j<i;j++) System.out.print(" ");
for(k=0;k<f.sum-2*i;k++) System.out.print("*");
System.out.println("*");
}
}
}
}
*/
import java.io.*;
public class J_square
{
static int rows;
static int half;
static int sum;
J_square() throws Exception
{
System.out.print("请输入您要输出的菱形的行数:");
rows=InputStream.read();
rows=rows-48;
if(rows%2==0)
{
System.out.println("请输入奇数!");
rows=0;
System.exit(-1);
}
half=rows/2;
sum=rows*2-2;
} public static void main(String args[]) throws Exception
{
J_square f=new J_square();
int i=0,j,k;
System.out.println(f.rows);
for(;i<f.rows;i++)
{
if(i<=f.half)
{
for(j=0;j<f.half-i;j++)
{
System.out.print(" ");
}
for(k=0;k<2*i;k++)
{
System.out.print("*");
if(i==f.half&&k==f.half) System.out.print("\b+");
}
System.out.println("*");
} else
{
for(j=f.half;j<i;j++) System.out.print(" ");
for(k=0;k<f.sum-2*i;k++) System.out.print("*");
System.out.println("*");
}
}
}
}
解决方案 »
- 2级级联菜单!
- [急]java.net.SocketException: Connection reset by peer: socket write error
- 哪位大侠有美化界面的skinlf.jar包,给我发一份啊。[email protected] 非常感谢
- Singleton
- 怎么把java 程序做成后台服务程序?
- 高手请进
- 关于打开文件的类(急!!!)
- 新手学习java遇到困难,请指点!
- 求证:某cell在数据库中的类型为int,用setValueAt((object)new Integer(cellValue).toSting())对吗?
- 这种编译方法对吗?如何将它做成可执行文件呢?
- 那位朋友知道如何用java运行本地程序并取回程序输出?
- 救命啊!大家谁知道在JAVA中如何判断当前时间是不是整点啊!急!先谢谢了!
String line = in.readLine();
int i = Integer.parseInt(line);
可以这样写吗?
但要知道怎么摆啊!