码迷,mamicode.com
首页 > 其他好文 > 详细

第一次考核

时间:2018-09-10 11:56:15      阅读:188      评论:0      收藏:0      [点我收藏+]

标签:scanner   tin   stat   next   oid   system   out   static   tom   

第一题

7-1 Hello World!

本题要求编写程序,输出一个短句“Hello World!”。

 

import java.util.Scanner;
public class Main {
public static void main(String args[]){
System.out.println("Hello World!");
}
}

 

第二题

7-2 求1到100的和

本题要求编写程序,计算表达式 1 + 2 + 3 + ... + 100 的值

 

import java.util.Scanner;
public class Main {
public static void main(String args[]){
int sum=0;
int i=1;
while(i<=100){
sum=sum+i;
i++;
}
System.out.println("sum = " +sum);
}
}

 

 

第三题

7-3 分段计算居民水费

为鼓励居民节约用水,自来水公司采取按用水量阶梯式计价的办法,居民应交水费y(元)与月用水量x(吨)相关:当x不超过15吨时,/;超过后,.。请编写程序实现水费的计算。

 

import java.util.Scanner;
public class Main {
public static void main(String args[]){
Scanner reader = new Scanner(System.in);
double x = reader.nextDouble();
if (x<=15){
double y =4*x/3;
System.out.printf("%.2f",y);
}
else{
double y =2.5*x-17.5;
System.out.printf("%.2f",y);
}
}
}

第四题

 

7-4 打印九九口诀表(20 分)

下面是一个完整的下三角九九口诀表:

1*1=1   
1*2=2   2*2=4   
1*3=3   2*3=6   3*3=9   
1*4=4   2*4=8   3*4=12  4*4=16  
1*5=5   2*5=10  3*5=15  4*5=20  5*5=25  
1*6=6   2*6=12  3*6=18  4*6=24  5*6=30  6*6=36  
1*7=7   2*7=14  3*7=21  4*7=28  5*7=35  6*7=42  7*7=49  
1*8=8   2*8=16  3*8=24  4*8=32  5*8=40  6*8=48  7*8=56  8*8=64  
1*9=9   2*9=18  3*9=27  4*9=36  5*9=45  6*9=54  7*9=63  8*9=72  9*9=81  

本题要求对任意给定的一位正整数N,输出从1*1N*N的部分口诀表。

 

import java.util.Scanner;
public class Main {
public static void main(String args[]){
Scanner reader = new Scanner(System.in);
int n = reader.nextInt();
for (int i = 1; i <=n;i++){
for (int j = 1;j <=i;j++){
if(j == i){
System.out.printf("%d*%d=%-4d\n",j,i,i * j);
}
else{
System.out.printf("%d*%d=%-4d",j,i,i * j);
}
}
}
}
}

 

 

第一次考核

标签:scanner   tin   stat   next   oid   system   out   static   tom   

原文地址:https://www.cnblogs.com/haoyuea/p/9618132.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!