2000字范文,分享全网优秀范文,学习好帮手!
2000字范文 > 将从键盘上输入的小写字母转换成大写字母输入

将从键盘上输入的小写字母转换成大写字母输入

时间:2022-10-11 07:37:58

相关推荐

将从键盘上输入的小写字母转换成大写字母输入

import java.io.*;

public class ByteArrayTest {

/*

*1、 本程序的目的 :编写一个把输入流中所有应为字母编程大写字母,然后将解惑写入到一个输出流对象的函数,用这个函数来讲一个字符串中的所有的字符转换成大写

*2、 System.in 连接到键盘,是InputStream类型的实例对象 System.out 连接到显示器,是PrintStream类的实例对象

*3、不管各种底层物理设备用什么方式实现数据的终止点,InputStream的read方法总是返回-1来表示输入流的结束

*4、 在windows下,按下crrl+z组合键可以产生键盘输入流的结束标记,在linux下,则是按下ctrl+d组合键产生输入流的结束标记

*5、建议 编程从键盘上连续读取一大段数据时,应尽量将读取的过程放在函数中完成,使用-1来作为键盘输入的结束点,在该函数中编写的程序代码不应直接使用System.in读取数据,而是用一个InputStream类型的形式参数来读取数据,然后将System.in作为实参传递给InputStream类型的形式参数来调用该函数

*6、屏幕的共享也可以运用ByteArrayInputStream和ByteArrayOutputStream流实现

*/

public static void main(String[] args) {

String stp = "abcdefghigh";

byte buf [] = stp.getBytes();

ByteArrayInputStream input = new ByteArrayInputStream(buf);

ByteArrayOutputStream output = new ByteArrayOutputStream();

transForm(input,output);

byte resault [] = output.toByteArray();

System.out.println(new String(resault));

//将字节数组中的所有元素拿出来转换成字符串

transForm(System.in,System.out);

//将从键盘输入的小写字母转换成大写的字母

}

public static void transForm(InputStream in,OutputStream out){

int info = 0;

try {

while((info = in.read()) != -1){

//读取信息

int uppInfo = Character.toUpperCase((char)info);

//将 读出的字节信息 转化成大写

out.write(uppInfo);

}

} catch (IOException e) {

e.printStackTrace();

}

}

}

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。