java中南大学livelab习题

上传人:第*** 文档编号:34198553 上传时间:2018-02-21 格式:DOC 页数:30 大小:339KB
返回 下载 相关 举报
java中南大学livelab习题_第1页
第1页 / 共30页
java中南大学livelab习题_第2页
第2页 / 共30页
java中南大学livelab习题_第3页
第3页 / 共30页
java中南大学livelab习题_第4页
第4页 / 共30页
java中南大学livelab习题_第5页
第5页 / 共30页
点击查看更多>>
资源描述

《java中南大学livelab习题》由会员分享,可在线阅读,更多相关《java中南大学livelab习题(30页珍藏版)》请在金锄头文库上搜索。

1、11.5 import java.util.*; public class Exercise01_01 public static void main(String args) System.out.println(9.5*4.5-2.5*3/(45.5-3.5);1.11(人口预测)基于以下假设美国人口普查局的项目群:每 7 秒一诞生一人死亡每 13 秒一个新移民每 45 秒编写一个程序,以显示人口为每个未来五年。假设目前的人口为 312032486 和一年有 365 天。1.3 P2numberExchange 将两个变量(a=10,b=20)的值交换,但要求不能使用额外的变量,只能通过简

2、单的运算实现!请在控制台上以a=? b=?的格式输出经过交互后的变量值。写程序读取 01000 范围之间的整数,并把读取的整数的各个位段上的数字相加 Enter a number between 0 and 1000: 999The sum of the digits is 27import java.util.*; public class Exercise02_06 public static void main(String args) Scanner sc=new Scanner(System.in);System.out.println(?0-1000?);int n;n=sc.ne

3、xtInt();int a,b,c;int m;a=n%10;b=(n/10)%10;c=n/100;m=a+b+c;System.out.println(m); 根据用户输入的时区信息,输出给定时区的当前时间 Enter the time zone offset to GMT: 5 The current time is 4:50:34import java.util.Date;import java.util.TimeZone;import java.text.SimpleDateFormat;public class Exercise02_08 public static void ma

4、in(String args)2SimpleDateFormat format=new SimpleDateFormat(yyyy-MM-dd hh:mm:ss);Date date=new Date();TimeZone zone=TimeZone.getTimeZone(GMT-5);format.setTimeZone(zone);System.out.println(format.format(date);给定两点坐标,计算两点的欧式距离 Enter x1 and y1: 1.5 -3.4 Enter x2 and y2: 4 5 The distance between the tw

5、o points is 8.764131445842194import java.util.Scanner;public class Exercise02_15 public static void main(String args)Scanner in=new Scanner(System.in);System.out.println(?x1,y1:);double x1=in.nextDouble();double y1=in.nextDouble();System.out.println(?x2,y2:);double x2=in.nextDouble();double y2=in.ne

6、xtDouble();double distance=Math.sqrt(Math.abs(x1-x2)*(x1-x2)+Math.abs(y1-y2)*(y1-y2);System.out.println(?:+distance); (Business: check ISBN-10 国际标准书号 ) An ISBN-10 (International Standard Book Number) consists of 10 digits: d1d2d3d4d5d6d7d8d9d10. The last digit, d10, is a checksum, which is calculate

7、d from the other nine digits using the following formula: (d1 * 1 + d2 * 2 + d3 * 3 + d4 * 4 + d5 * 5 +d6 * 6 + d7 * 7 + d8 * 8 + d9 * 9) % 11If the checksum is 10, the last digit is denoted as X according to the ISBN-10 convention. Write a program that prompts the user to enter the first 9 digits a

8、nd displays the 10-digit ISBN (including leading zeros). Your program should read the input as an integer. Here are sample runs:Enter the first 9 digits of an ISBN as integer: 013601267 The ISBN-10 number is 0136012671Enter the first 9 digits of an ISBN as integer: 013031997The ISBN-10 number is 013

9、031997Ximport java.util.Scanner;public class Exercise03_09 public static void main(String args)System.out.println(Enter the first 9 digits of an ISBN as integer:);Scanner n=new Scanner(System.in);int a=new int9;int i;3int s=0;for(i=0;i(w1+w2)&Math.abs(y1-y2)(h1+h2)System.out.println(?);elseif(Math.a

10、bs(x1-x2)15)System.out.println(input+ is an invalid input);break;else sinput=Integer.toHexString(input).toUpperCase();System.out.println(sinput);写程序判断用户输入的字母是否是元音?import java.lang.Character;import java.util.*;public class Exercise04_13 public static void main(String args)for(int i=0;i0)str1=strj;str

11、j=strj+1;strj+1=str1;System.out.println(The three cities in alphabetical order are:);System.out.println(str0+#+str1+#+str2);9(Count positive and negative numbers and compute the average of numbers) Write a program that reads an unspecified number of integers, determines how many positive and negativ

12、e values have been read, and computes the total and average of the input values (not counting zeros). Your program ends with the input 0. Display the average as a floating-point number.(计数正数和负数并且计算数的平均),写程序,读取整数数目不详,确定多少正值和负值都被读出,与输入值的总和和平均计算(不包括零)。与输入 0 显示器平均为浮点数程序结束。import java.util.Scanner;public

13、 class Exercise05_01 public static void main(String args)int num;int i=0,pnum=0,nnum=0;double ave,sum=0;System.out.println(Enter an integer, the input ends if it is 0: );Scanner sc=new Scanner(System.in);num=sc.nextInt();while(num!=0)i+;if(num0)pnum+;else nnum+;sum+=num;num=sc.nextInt();ave=sum/(dou

14、ble)i;sc.close();System.out.println(The number of positives is +pnum);System.out.println(The number of negatives is +nnum);System.out.println(The total is +sum);System.out.println(The average is +ave);(Find numbers divisible by 5 or 6, but not both) Write a program that displays all the numbers from

15、 100 to 200, ten per line, that are divisible by 5 or 6, but not both. Numbers are separated by exactly one space.(发现数整除 5 或 6,但不能两者都)写显示从 100 到200 的所有数字,10 每行,即是整除 5 或 6 的程序,但不能同时使用。数字是由一个空格隔开。public class Exercise05_11 public static void main(String args)for(int i=100;i=0;j-)System.out.print( );for(int k=i;k0;k-)System.out.print(k);for(int k=2;k0;i-)sum2+=1/(double)i;System.out.println(The sum from left to right:+sum1);System.out.println(The sum from right to left:+sum2);(Display calendars) Write a program that prompts the user to enter the year and first day of the year and displays

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 办公文档 > 解决方案

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号