第一次过程性考核

码云仓库:   https://gitee.com/ahy16012003/codes  

 

 第一题

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

(2)代码:

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

(3)设计思路:直接输出System.out.println(Hello world!);

(4)运用的知识点:System.out,println();

(5)运行结果:Hello World!

 

  第二题

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

(2)代码:

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

(3)设计思路:应用循环  ,自加

(4)运用知识点:i++ ;   System.out,println()

  (5)  运行结果:sum = 5050

 

  第三题

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

(2)代码:

import java.util.Scanner;
public class Main {
public static void main (String args[]){

Scanner ahy = new Scanner(System.in);
double x,y;
x = ahy.nextDouble();
if(x<=15){
y=x*4/3;
}
else{
y=2.5*x-17.5;
}
System.out.printf("%.2f",y);
}
}

(3)设计思路:要求输入,所以运用输入输出语句;有不同的收费标准,所以运用if else 判断语句;要求保留小数点后两位,%.2f。

(4)运用知识点:if...else... ; double ; 

  (5) 运行结果:22.50

 

  第四题

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

(2)代码:

import java.util.Scanner;
public class Main {
public static void main (String args[]){
Scanner ahy = new Scanner(System.in);
int n = ahy.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);
}
}
}
}
}

(3)设计思路:运用了for循环,进行判断;要求等号后面占四位,%-4d。        

(4)运用知识点:for循环;if...else...

  (5) 运行结果:

3

1*1=1

1*2=2   2*2=4

1*3=3   2*3=6   3*3=9

posted @ 2018-09-14 17:27  草莓草莓  Views(258)  Comments(0Edit  收藏  举报