今天有时间练习下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) { }
}
}
阅读(12053) | 评论(0) | 转发(0) |