<p><span style="font-size: 14px; line-height: 26px; text-align: -webkit-center; font-family: SimSun;"></span>------<a href="http://www.itheima.com" target="blank">Java培训、Android培训、iOS培训、.Net培训</a>、期待与您交流! -------<span style="font-family: Arial; font-size: 14px; line-height: 26px; text-align: -webkit-center;"></span>
</p>
1. 字符的读入:
1)
Scanner input = new Scanner(System.in);
String str = input.next();
char ch = str.CharAt(0);
Java中没有直接读入单个字符的函数,所以可以用字符串的 式读入,然后取出。
2)
DataInputStream input = new DataInputStream(System.in);
char ch = input.readChar();
直接以字节的方式读入,但以字节方式读入, 会对后面的使用有一定的影响。
2. 产生随机数或随机字符
1) 产生随机数:
int int_a = intput.nextInt();
int int_b = input.nextInt();
int random = (int _a + Math.random()*(int_a - int_b + 1));
产生a~b之间的数字(包括a和b)
2) 产生随机字符:
Char ch = (char)(ch1 + Math.random()*(ch2 - ch1 + 1));
产生a~b之间的字符(包括a和b)。
3. 包中类的使用
1) public使得类、方法和数据域可以在任何类中访问。
2) private使得方法和数据域只能从他自己所在的类中访问,且只能
修饰数据和方法,不能修饰整个类(内部类除外)。
3) 默认情况下,类、方法可以从同一个包中的任何类中访问,这是成
为包私有的。
4) class_a和class_b,变量和方法可以互相调用,若class_a调用
class_b中的变量和方法,形式为:
Class_b.value_b;
Class_b.meathed_b(value_a,value_a);
4. 增强的for循环
for(int i:array)
System.out.println(i);
array为数组名字,i为数组中的要输出的数,int 为数组的类型。