TA的每日心情 | 开心 2021-3-12 23:18 |
---|
签到天数: 2 天 [LV.1]初来乍到
|
这是一个简单的输出菱形的程序。- import java.io.*;
- public class YangHuiSanJiao{
- public static void blank(int x){
- for(int c=0;c< x;c++){
- System.out.print(" ");
- }
-
- }
- public static void star(int y){
- for(int d=0;d< y;d++){
- System.out.print("*");
- System.out.print(" ");
- }
-
- }
复制代码
- public static void main(String args[]){
- String st;
- BufferedReader bu;
- int number;
- try{
- System.out.print("请输入菱形的大小:");
- bu=new BufferedReader(new InputStreamReader(System.in));
- st=bu.readLine();
- }
- catch(IOException e){
- System.out.println("不是数字型");
- return;
- }
- try{
- number=Integer.parseInt(st);
- }
- catch(NumberFormatException h){
- System.out.println("输入值为非数值");
- return;
- }
-
- for (int m=number;m>=0;m--){
- blank(m);
- star(number-m);
- blank(m-1);
- System.out.println();
- }
- for (int m=1;m< number;m++){
- blank(m);
- star(number-m);
- blank(m-1);
- System.out.println();
- }
-
- }
- }
复制代码 这是程序的运行图:
- C:java>java YangHuiSanJiao
- 请输入菱形的大小:10
- *
- * *
- * * *
- * * * *
- * * * * *
- * * * * * *
- * * * * * * *
- * * * * * * * *
- * * * * * * * * *
- * * * * * * * * * *
- * * * * * * * * *
- * * * * * * * *
- * * * * * * *
- * * * * * *
- * * * * *
- * * * *
- * * *
- * *
- *
- C:java>
复制代码
function TempSave(ElementID)
{
CommentsPersistDiv.setAttribute("CommentContent",document.getElementById(ElementID).value);
CommentsPersistDiv.save("CommentXMLStore");
}
function Restore(ElementID)
{
CommentsPersistDiv.load("CommentXMLStore");
document.getElementById(ElementID).value=CommentsPersistDiv.getAttribute("CommentContent");
}
源码下载:http://file.javaxxz.com/2014/10/1/065328422.zip |
|