云南大学JAVA程序设计实验
云南大学软件学院
实 验 报 告
序 号: 实验老师: 陆歌皓 课程名称: 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){ 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);