10.2日报
今天学习并运行了如下程序:
import java.util.*;
public class InputTest {
public class InputTest {
public static void main(String[] args) {
// TODO 自动生成的方法存根
Scanner in = new Scanner(System.in);
// TODO 自动生成的方法存根
Scanner in = new Scanner(System.in);
// get first input
System.out.print("What is your name? ");
String name = in.nextLine();
System.out.print("What is your name? ");
String name = in.nextLine();
// get second input
System.out.print("How old are you? ");
int age = in.nextInt();
/* int i;
String value="100";
i=Integer.parseInt(value);
i=200;
String s=String.valueOf(i);*/
// display output on console
System.out.println("Hello, " + name + ". Next year, you'll be " + (age + 1));
}
System.out.print("How old are you? ");
int age = in.nextInt();
/* int i;
String value="100";
i=Integer.parseInt(value);
i=200;
String s=String.valueOf(i);*/
// display output on console
System.out.println("Hello, " + name + ". Next year, you'll be " + (age + 1));
}
}
程序运行结果是:
What is your name? chendongliang
How old are you? 21
Hello, chendongliang. Next year, you'll be 22
How old are you? 21
Hello, chendongliang. Next year, you'll be 22
如下程序:
public class RandomStr {
public static void main(String[] args) {
// TODO 自动生成的方法存根
//定义一个空字符串
String result = "";
//进行6次循环
for(int i = 0 ; i < 6 ; i ++)
{
//生成一个97~122的int型的整数
int intVal = (int)(Math.random() * 26 + 97);
//将intValue强制转换为char后连接到result后面
result = result + (char)intVal;
}
//输出随机字符串
System.out.println(result);
}
// TODO 自动生成的方法存根
//定义一个空字符串
String result = "";
//进行6次循环
for(int i = 0 ; i < 6 ; i ++)
{
//生成一个97~122的int型的整数
int intVal = (int)(Math.random() * 26 + 97);
//将intValue强制转换为char后连接到result后面
result = result + (char)intVal;
}
//输出随机字符串
System.out.println(result);
}
}
程序运行结果:
lhihnb