1 Java 语言
2 //package main
3 //注意不要添加包名称,否则会报错。
4
5 import java.io.*;
6 import java.util.*;
7 cin.hasNext();
8 cin.hasNextLine();
9 cin.hasNextBigDecimal();
10 cin.hasNextBigInteger();
11 cin.hasNextBoolean();
12 cin.hasNextByte();
13 cin.hasNextDouble();
14 cin.hasNextInt();
15 cin.hasNextLong();
16 public class Test {
17 public static void main(String args[])
18 {
19 Scanner cin = new Scanner(System.in);
20 int a, b;
21 while(cin.hasNextInt())//判断cin中是否还有值
22 {
23 a = cin.nextInt();
24 b = cin.nextInt();
25 System.out.println(a + b);
26 }
27 }
28 }
29 public static void main(String args[])
30 {
31 int x=1;
32 int y=~1;
33 System.out.println(Integer.toBinaryString(x));//1
34 System.out.println(Integer.toBinaryString(y));//1111111111111111111111111110
35 System.out.println(y);//-2
36 }
37 * 测试3:从文本文件中读取数据
38 */
39 static void testExample03(){
40 //1、在内存中打开要读取文件的字符流对象
41 try {
42 Reader reader=new FileReader("e:/ReadMe.log");
43
44 //循环读取,一次就读一个
45 int ch=reader.read();
46 StringBuffer buffer=new StringBuffer();
47 while(ch!=-1){ //读取成功
48 buffer.append((char)ch);
49 ch=reader.read();
50 }
51 System.out.println(buffer.toString());
52 //3、关闭流
53 reader.close();
54 } catch (FileNotFoundException e) {
55 System.out.println("要读取的文件不存在:"+e.getMessage());
56 } catch (IOException e) {
57 System.out.println("文件读取错误:"+e.getMessage());
58 }
59 }
60 /**
61 * 测试4:向文本文件中写入数据
62 */
63 static void testExample04(){
64 System.out.println("请输入内容:");
65 String text=input.next();
66 try {
67 //1、打开流
68 Writer w=new FileWriter("e:/测试.txt",true);
69 //2、写入内容
70 w.write(text);
71 //3、关闭流
72 w.close();
73 } catch (IOException e) {
74 System.out.println("文件写入错误:"+e.getMessage());
75 }
76 }
77 #!/usr/bin/env python
78 # coding=utf-8
79 # Python使用的是2.7,缩进可以使用tab、4个空格或2个空格,但是只能任选其中一种,不能多种混用
80 while 1:
81 a=[]
82 s = raw_input()
83 # raw_input()里面不要有任何提示信息
84 if s != "":
85 for x in s.split():
86 a.append(int(x))
87
88 print sum(a)
89 else:
90 break
91
92 //C语言
93 #include <iostream.h> //数据流输入/输出
94 #include <math.h> //定义数学函数
95 #include <stdio.h> //定义输入/输出函数
96 #include <stdlib.h> //定义杂项函数及内存分配函数
97 #include <string.h> //字符串处理
98 #include <stdio.h>
99 int main()
100 {
101 int a, b;
102 while(scanf("%d%d", &a, &b) != EOF)
103 printf("%d\n", a + b);
104 system("pause");
105 }
106
107
108 //C++语言
109 #include <iostream>
110 using namespace std;
111 int main()
112 {
113 int a, b;
114 while(cin>> a >> b)
115 cout << a + b << endl;
116 return 0;
117 }
118
119
120 介绍1:Java的输入控制
121 测试2:测试输出x=1 和y=~1
122 测试3:从文本文件中读取数据
123 测试4:向文本文件中写入数据