Skip to content

Commit 155ceb1

Browse files
committed
2017.3
1 parent 726a108 commit 155ceb1

File tree

3 files changed

+95
-0
lines changed

3 files changed

+95
-0
lines changed

Diff for: GUI/draw.java

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import java.awt.Graphics;
2+
import javax.swing.JPanel;
3+
public class draw extends JPanel{
4+
public void paintComponent(Graphics g)
5+
{
6+
super.paintComponent(g);
7+
8+
int width = getWidth();
9+
int height= getHeight();
10+
11+
g.drawLine(0, 0, width, height);
12+
g.drawLine(0, height, width,0);
13+
}
14+
15+
}

Diff for: GUI/drawTest.java

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import javax.swing.JFrame;
2+
public class drawTest {
3+
public static void main(String[] args)
4+
{
5+
draw panel=new draw();
6+
JFrame application = new JFrame();
7+
application.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
8+
application.add(panel);
9+
application.setSize(650, 650);
10+
application.setVisible(true);
11+
}
12+
13+
}

Diff for: IO.java

+67
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
package 实验一;
2+
import java.util.*;
3+
import java.io.*;
4+
public class IO {
5+
public static void main(String[] args) throws IOException
6+
{
7+
8+
//way1:use Scanner to input
9+
Scanner input=new Scanner(System.in);
10+
System.out.print("输入一个字符串和数字:");
11+
String a=input.next();
12+
int number=input.nextInt();
13+
14+
//way2:use BufferedReader and System.in to input
15+
System.out.print("输入一个字符串和数字:");
16+
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
17+
String b;
18+
b=br.readLine();
19+
int s;
20+
s =Integer.parseInt(br.readLine());
21+
22+
23+
//two ways to output
24+
System.out.print(a);
25+
System.out.println(number);
26+
System.out.print(b);
27+
System.out.println(s);
28+
// PrintStream out = new PrintStream( new BufferedOutputStream(System.out));
29+
// out.print(s);
30+
31+
32+
//题目二
33+
String s1,s2;
34+
s1=s2=null;
35+
int num1,num2;
36+
37+
System.out.print("Please input two number:");
38+
s1=br.readLine();
39+
s2=br.readLine();
40+
if(s1.length()==0||s2.length()==0)
41+
{
42+
System.out.print("erro!");
43+
return;
44+
} //有空字符串报错
45+
for(int i=0;i<s1.length();i++)
46+
{
47+
if(s1.charAt(i)>'9'||s1.charAt(i)<'0')
48+
{
49+
System.out.print("erro!");
50+
return;
51+
}
52+
}
53+
for(int i=0;i<s2.length();i++)
54+
{
55+
if(s2.charAt(i)>'9'||s2.charAt(i)<'0')
56+
{
57+
System.out.print("erro!");
58+
return;
59+
}
60+
} //只要s1,s2中有非数字的字符就报错退出
61+
num1=Integer.parseInt(s1);
62+
num2=Integer.parseInt(s2); //若没问题,则转为数字
63+
System.out.print("The average of the two numbers is: ");
64+
System.out.print((num1+num2)/2);
65+
}
66+
67+
}

0 commit comments

Comments
 (0)