Chinaunix首页 | 论坛 | 博客
  • 博客访问: 373475
  • 博文数量: 75
  • 博客积分: 1486
  • 博客等级: 上尉
  • 技术积分: 675
  • 用 户 组: 普通用户
  • 注册时间: 2010-07-22 18:38
个人简介

...

文章分类
文章存档

2023年(1)

2021年(3)

2020年(2)

2018年(1)

2017年(1)

2016年(10)

2015年(34)

2011年(14)

2010年(9)

分类: Java

2011-06-23 16:31:36


今天有时间练习下Java,虽然不是很精通Java,但是还是小有收获的
程序的基本功能是输入几个数字,然后计算其表示的直线,并且在模拟的坐标中描出输入的点
程序如下:
通过编译
javac InputTest.java
java  InputTest
根据编译器的不同,程序的编译情况会不同,所以这个是要注意的!!
/*
 *  InputTest.java
 */
import java.io.*;
import java.text.*;
import java.util.*;

public class InputTest
{
    public static void main(String[] args)
    {
        try {
            BufferedReader buf = new BufferedReader(new InputStreamReader(System.in));   
            System.out.print("Enter X1: ");
            double x1=Integer.parseInt(buf.readLine());

            System.out.print("Enter Y1: ");
            double y1=Integer.parseInt(buf.readLine());

            System.out.print("Enter X2: ");
            double x2=Integer.parseInt(buf.readLine());

            System.out.print("Enter Y2: ");
            double y2=Integer.parseInt(buf.readLine());

            double    re = (y1-y2)/(x1-x2);
            double    af = y2-x2*re;
            DecimalFormat df = new DecimalFormat("##.00");
            re = Double.parseDouble(df.format(re));
            DecimalFormat dff = new DecimalFormat("##.00");
            af = Double.parseDouble(dff.format(af));
            
            System.out.println("\n\ny="+re+"x+"+af+"\n\n");

            for (int i=9; i>=0; i--) {
                //System.out.print(i+"|");
                if( ((i == y1) && (x1 == 0)) || ((i == y2) && (x2 == 0)) ) {
                    System.out.print(i+" *");
                } else {
                    System.out.print(i+" |");
                }
                //System.out.print(i+"|");

                for(int j=0; j<10; j++) {
                    if( ((i == y1) && (j == x1) && (j != 0)) ||
                            ((i == y2) && (j == x2) && (j != 0)) ) {
                        System.out.print("*");
                    } else {
                        System.out.print("  ");
                    }
                }
                if(i == 0) {
                    System.out.print("\r"+i+" |");
                    for(int r=10; r>0; r--) {
                        if(r == 10) {
                            System.out.print("_");
                        }else {
                            System.out.print("__");
                        }
                    }

                    System.out.print("\n");
                    System.out.print("  ");
                    for(int r=0; r<10; r++)
                        System.out.print(" "+r);
                }
                System.out.print("\n");
            }
        } catch(IOException e) { }
    }
}


阅读(12000) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~