下载本文档
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、(浪曦分享)java基础程序设计学习java使用system.out来表示标准输出设备,使用system.in来表示标准输入设备。java并不直接支持控制台输入,但是可以使用scanner类创建它的对象,以读取来自system.in的输入。scanner input = new scanner(system.in);scanner对象的方法:方法描述nextbyte()读取一个byte类型的整数nextshort读取一个short类型的整数nextint()读取一个int类型的整数nextlong()读取一个long类型的整数nextfloat()读取一个float类型的数nextdouble
2、()读取一个double类型的数next()读取一个字符串,该字符串在一个空白符之前结束nextline()读取一行文本,以回车键结束代码1(求圆的面积):12345678910111213141516public class main public static void main(string args) scanner input =new scanner(system.in); system.out.print("enter a number for radius: "); double radius = input.nextdouble(); double are
3、a = radius * radius *3.1415926; system.out.println("the area for the circle of radius " + radius +" is " + area); /*enter a number for radius: 23.45the area for the circle of radius 23.45 is 1727.5696247214998*/代码2(求输入三个数的平均值):123456789101112131415public class main public static
4、void main(string args) scanner input =new scanner(system.in); system.out.print("enter three numbers: "); double num1, num2, num3, average; num1 = input.nextdouble(); num2 = input.nextdouble(); num3 = input.nextdouble(); average = (num1 + num2 + num3) /3; system.out.println("the averag
5、e of" + num1 +" " + num2 +" " + num3 +" is " + average); java中使用final关键字表示一个变量是常量string类型不是基本类型,而是引用类型。可以进行字符串连接,使用“+”连接符,如果操作数之一不是字符串,非字符串值先转换为字符串,再与另一个字符串连接起来“+=”也可以用于字符串12345678910111213141516public class main public static void main(string args) string message
6、="welcome " +"to " +"java" int i =1, j =2; string s ="chapter" +2; string s1 ="supplement" +'b' system.out.println(message); /welcome to java system.out.println(s); /chapter2 system.out.println(s1); /supplementb message +="and java is fu
7、n!" system.out.println("i + j is " + i + j); /i + j is 12 system.out.println("i + j is " + (i + j); /i + j is 3 为从控制台读取字符串,调用scanner对象上的next()方法:1234567891011121314public class main public static void main(string args) scanner input =new scanner(system.in); system.out.printl
8、n("enter three strings: "); string s1 = input.next(); string s2 = input.next(); string s3 = input.next(); system.out.println("s1 is " + s1); system.out.println("s2 is " + s2); system.out.println("s3 is " + s3); next()方法读取以空白字符结束的字符串(' '、't'、'f'、'r'、'n')可以使用nextline()方法读取一整行文本。nextline()方法读取以按下回车键为结束标志的字符串:12345678910public class main public static void main(string args) scanner input =new scanner(system.in); system.out.p
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 计算机科学与技术的发展方向
- 视网膜剥脱复位术护理
- 颅脑损伤患者意识恢复期的护理实践与体会
- 2024年秋季学期新苏科版八年级上册物理课件 第四章 物态变化 第五节 水循环
- 2024年秋季学期新人教版数学一年级上册课件 第1单元 5以内数的认识和加、减法 3 0的认识和加、减法 0的认识和加、减法
- 钛铁产品原材料供应与需求分析
- 环保节能型冷却塔市场需求与消费特点分析
- 锤纹助剂产品营销计划书
- 蒸汽疏水阀商业机会挖掘与战略布局策略研究报告
- 非机械驱动车辆产品原材料供应与需求分析
- 2024新苏教版一年级数学册第三单元第1课《图形的初步认识》课件
- 2024年高校教师资格证资格考试试题库及答案(各地真题)
- (正式版)HGT 22820-2024 化工安全仪表系统工程设计规范
- 工程招投标流程图
- 新人教版七年级英语下册:短文填词专练
- 网球教学计划表
- 四川省破格申报专业技术职务任职资格审核表
- 海南省基本医疗保险参保人意外伤害认定表(全省职工医保和城乡居民医保统一用此表)
- 六氟化硫电气运行、试验及检修人员安全防护细则
- 离合器教案(共8页)
- codesys所有函数的详细说明(可编辑修改word版)
评论
0/150
提交评论