第一范文网 - 专业文章范例文档资料分享平台

JAVA编程题全集(100题及答案)

来源:用户分享 时间:2025/5/17 16:26:23 本文由loading 分享 下载这篇文档手机版
说明:文章内容仅供预览,部分内容可能不全,需要完整文档或者需要复制内容,请下载word后使用。下载word有问题请添加微信号:xxxxxxx或QQ:xxxxxx 处理(尽可能给您提供完整文档),感谢您的支持与谅解。

{

for(int i=0;i<=str1.length()-str2.length();i++) {

if(str2.equals(str1.substring(i, str2.length()+i))) //这种比法有问题,会把\看成有2个\子串。 count++; }

System.out.println(\子串在字符串中出现: \次\} } }

【程序50】

题目:有五个学生,每个学生有3门课的成绩,从键盘输入以上数据(包括学生号,姓名,三门课成绩),计算出平均成绩,把原有的数据和计算出的平均分数存放在磁盘文件 \\中。

import java.io.*; import java.util.*;

public class lianxi50 {

public static void main(String[] args){ Scanner ss = new Scanner(System.in); String [][] a = new String[5][6]; for(int i=1; i<6; i++) {

System.out.print(\请输入第\个学生的学号:\ a[i-1][0] = ss.nextLine();

System.out.print(\请输入第\个学生的姓名:\ a[i-1][1] = ss.nextLine(); for(int j=1; j<4; j++) {

System.out.print(\请输入该学生的第\个成绩:\ a[i-1][j+1] = ss.nextLine(); }

System.out.println(\ }

//以下计算平均分 float avg; int sum;

for(int i=0; i<5; i++) { sum=0;

for(int j=2; j<5; j++) {

sum=sum+ Integer.parseInt(a[i][j]); }

avg= (float)sum/3;

a[i][5]=String.valueOf(avg); }

//以下写磁盘文件

String s1; try {

File f = new File(\ if(f.exists()){

System.out.println(\文件存在\ }else{

System.out.println(\文件不存在,正在创建文件\ f.createNewFile();//不存在则创建 }

BufferedWriter output = new BufferedWriter(new FileWriter(f)); for(int i=0; i<5; i++) { for(int j=0; j<6; j++) { s1=a[i][j]+\ output.write(s1); } }

output.close();

System.out.println(\数据已写入c盘文件stud中!\ } catch (Exception e) { e.printStackTrace(); } } }

搜索更多关于: JAVA编程题全集(100题及答案) 的文档
JAVA编程题全集(100题及答案).doc 将本文的Word文档下载到电脑,方便复制、编辑、收藏和打印
本文链接:https://www.diyifanwen.net/c00bwp6a3hb75clm2zb6d_11.html(转载请注明文章来源)
热门推荐
Copyright © 2012-2023 第一范文网 版权所有 免责声明 | 联系我们
声明 :本网站尊重并保护知识产权,根据《信息网络传播权保护条例》,如果我们转载的作品侵犯了您的权利,请在一个月内通知我们,我们会及时删除。
客服QQ:xxxxxx 邮箱:xxxxxx@qq.com
渝ICP备2023013149号
Top