文档详情

云南大学JAVA程序设计实验四.doc

发布:2016-04-01约3.28千字共8页下载文档
文本预览下载声明
指标等级 A B C D 功能完整 程序质量 按时检查 提问回答 检查时间 总评成绩 云南大学软件学院 实 验 报 告 课程名称: JAVA程序设计实验 实验名称: lab4 学 号: 20111120279 姓 名: 李张昱 一、实验目的 练习Java基本编程结构,包括字符串,输入输出等。 二、实验内容 1.Program 1 Write a program called String1.java and do the following:? Create a String object that accepts input from the user.? Referencing the JDK docs, execute 2 different methods on the String.? Print the results of the methods.? Result: Input a string: How are you length of string is 11 first 5 bytes of string are How a 根据实验要求写了以下程序: package lab4; import java.util.*; public class String1 { public static void main(String[] args){ Scanner in=new Scanner(System.in); System.out.println(Input a string:); String str=in.nextLine(); int n=str.length(); String substr=str.substring(0,5); System.out.println(lenth of string is +n); System.out.println(first 5 bytes of string are +substr); } } 2.Program 2 Write a program called StringTokenizer1.java that accepts a string, looks for commas within the string, and breaks the string up into the parts separated by the comma.? For example, the string Kunming, Yunnan, China would return three strings: String1 = Kunming String2 = Yunnan String3 = China 根据实验要求写了以下程序: package lab4; import java.util.*; public class StringTokenizer1 { public static void main(String[] args){ Scanner in=new Scanner(System.in); System.out.println(Please input a string seperated by comma:); String str=in.nextLine(); String [] a=str.split(,); for(int i=0;ia.length;i++) System.out.println(String+(i+1)+=+a[i]); } } 3.Program 3 Design and write a Java class named SalesArray.java that will: Declare a two-dimensional integer array named sales.? Populate the first four columns using the following data. Quarter 1 Quarter 2 Quarter3 Quarter 4 Total Dept. 1 750 660 910 800 Dept. 2 800 700 950 900 Dept. 3 700 600 750 600 Dept. 4 850 800 1000 950 Dept. 5 900 800 960 980 Total Write a loop to compute a
显示全部
相似文档