
正文
java写英语代码怎么写 java写英语代码怎么写出来
提示:扫一扫查出行【扫一扫了解最新限行尾号】
复制提示
用java编写程序 1.建立一个文本文件,输入英语短文.编写一个程序,统计该文件中英文字母的个数,
public class Read {
public static void main(String[] args) throws Exception {
long size = readFileByChars("D://test.txt");
write("D://test1.txt",size);
}
public static long readFileByChars(String fileName) {
File file = new File(fileName);
Reader reader = null;
int num =0;
try {
reader = new InputStreamReader(new FileInputStream(file));
int tempchar;
while ((tempchar = reader.read()) != -1) {
// 对于windows下java写英语代码怎么写,rn这两个字符在一起时java写英语代码怎么写,表示一个换行。
// 但如果这两个字符分开显示时,会换两次行。
// 因此,屏蔽掉r,或者屏蔽n。否则,将会多出很多空行。
if (((char) tempchar) != 'r') {
System.out.print((char) tempchar);
}
if (tempchar= 'A' tempchar= 'Z' ||tempchar= 'a' tempchar= 'z'){
num++;
}
}
reader.close();
} catch (Exception e) {
e.printStackTrace();
} finally {
if (reader != null) {
try {
reader.close();
} catch (IOException e1) {
}
}
}
return num;
}
public static void write(String fileName,long size) throws IOException {
File file = new File(fileName);
Writer writer = null;
try {
writer =new FileWriter(new File(fileName));
writer.write("英文字母共有:"+size);
}catch (Exception e){
e.printStackTrace();
}finally {
if (writer!= null){
writer.close();
}
}
}
}
第二题java写英语代码怎么写:
public class Read {
public static void main(String[] args) throws Exception {
readFile("D://test.txt");
}
public static void readFile(String fileName ) throws Exception {
BufferedReader isr = new BufferedReader(new FileReader(fileName));
String str = null;
int allnumber =1;
str = isr.readLine();
String [] strings = str.split("\\s+");
float [] sum ={Float.valueOf(strings[0]),Float.valueOf(strings[1]),Float.valueOf(strings[2])};
float [] min ={Float.valueOf(strings[0]),Float.valueOf(strings[1]),Float.valueOf(strings[2])};
float [] max ={Float.valueOf(strings[0]),Float.valueOf(strings[1]),Float.valueOf(strings[2])};
System.out.println(str);
while ((str = isr.readLine())!= null){
System.out.println(str);
deal(str,sum,min,max);
allnumber++;
}
if (isr!= null){
isr.close();
}
System.out.println("三门课最大值java写英语代码怎么写:"+max[0]+"\t"+max[1]+"\t"+max[2]);
System.out.println("三门课最小值:"+min[0]+"\t"+min[1]+"\t"+min[2]);
System.out.println("三门课平均值:"+sum[0]/allnumber+"\t"+sum[1]/allnumber+"\t"+sum[2]/allnumber);
}
public static void deal(String str, float[] sum, float[] min, float[] max){
String [] strings = str.split("\\s+");
for (int i=0;i3;i++) {
sum[i] = sum[i] + Float.valueOf(strings[i]);
if (max[i] Float.valueOf(strings[i])) {
max[i] = Float.valueOf(strings[i]);
}
if (min[i] Float.valueOf(strings[i])) {
min[i] = Float.valueOf(strings[i]);
}
}
}
}
相关问答
Q1: 用JAVA编写程序,把一个英语句子译成数字代码。急用!!!必须用JAVA写啊!
public static String translate(String value) {
StringBuffer result = new StringBuffer();
char[] valueChars = value.toCharArray();
String temp = null;
for (char c : valueChars) {
if (c = 'a' c = 'z') {
temp = c - 'a' + 1 + "";
if (temp.length() == 1) {
result.append("0");// 补零,不然还原不回来
}
} else if (c = 'A' c = 'Z') {
temp = c - 'A' + 27 + "";//应该是27刚刚26错java写英语代码怎么写了
} else if (c == ' ') {
temp = "*";
} else {
temp = c + "";
}
result.append(temp);
}
return result.append(".").toString();
}
Q2: 编写Java程序,要求在命令行窗口输出二十六个英文字母的大小写。
public class PrintLetter
{
public static void main(String args [])
{
PrintLetter pl = new PrintLetter();
pl.printLowerCase ();
pl.printUpperCase ();
}
void printLowerCase ()
{
System.out.println("\n");
char a='a';
for(int i=0;i26;i++)
{
System.out.print(a+" ");
a++;
}
}
void printUpperCase ()
{
System.out.println("\n");
char a='A';
for(int i=0;i26;i++)
{
System.out.print(a+" ");
a++;
}
}
}
Q3: 用JAVA编一个程序输出全部的英文字母
编码思路
首先考虑到,英文字母的ASCII码是按字母顺序连续的整数,所以可以采用起始字母A递增的方式进行打印
英文字母有大小写之分,大小写字母的ASCII码是不连续的,所以需要分别打印
示例代码
public static void main(String[] args) {
char uc = 'A';
char lc = 'a';
//保存全部大写字母
StringBuilder upperCaseLetters = new StringBuilder("UpperCaseLetters:");
//保存全部小写字母
StringBuilder lowerCaseLetters = new StringBuilder("LowerCaseLetters:");
for (int i = 0; i 26; i++) {
upperCaseLetters.append((char) (uc + i));
lowerCaseLetters.append((char) (lc + i));
}
System.out.println(upperCaseLetters);
System.out.println(lowerCaseLetters);
}
注意事项
不建议将上述变量uc硬编码赋值为65。反之,则可以提高程序的可读性,省去了不必要的注释,也体现出了可移植性的思想。
关于java写英语代码怎么写和java写英语代码怎么写出来的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站。







