java基础第五章上机题_java语⾔程序设计基础篇第五章编程练
习题
1
import java.util.Scanner;
marquee 属性public class Main{
public static void main(String[] args){
Scanner input = new Scanner(System.in);
double sum = 0;
int total;
int positive = 0;
int negative = 0;
while(true){
double num = Double();
if(num == 0)
break;
sum += num;
if(num > 0)
wxpython多窗口
++positive;
else if(num < 0)
++negative;
}
System.out.println(positive + "\n" + negative + "\n" + sum + "\n" + sum / (positive+negative));
}
}
2
import java.util.Scanner;
public class Main{
public static void main(String[] args){
final int NUMBER_OF_QUESTIONS = 10;
int correctCount = 0;
int count = 0;
long startTime = System.currentTimeMillis();
String output = " ";
Scanner input = new Scanner(System.in);
while(count < NUMBER_OF_QUESTIONS){
int number1 = (int)(Math.random()*15+1);
int number2 = (int)(Math.random()*15+1);
System.out.print("What is " + number1 + " + " + number2 + " ? ");
int answer = Int();
if(number1 + number2 == answer){
System.out.println("You are correct!");
++correctCount;
}
else
System.out.println("Your answer is wrong.\n" + number1 + " + " + number2
+ " should be " + (number1+number2));
++count;
output += "\n" + number1 + " + " + number2 + " = " + answer +
((number1 + number2 == answer) ? " correct" : " wrong");
}
long endTime = System.currentTimeMillis();
long testTime = endTime - startTime;
System.out.println("Correct count is " + correctCount + "\nTest time is " + testTime/1000 + " seconds\n" + output);
}
}
3
public class Main {
public static void main(String[] args){
System.out.println("千克 磅");
for(int i = 1; i < 200; ++i){
if(i%2 == 1)
System.out.println(i + " " + i*2.2);
}
}
}
4 5 6
同上
7
import java.util.Scanner;
public class Main{
public static void main(String[] args){
double base = 10000.0;
double num = base;
for(int i = 0; i < 10; ++i){
num += num*0.05;
}
double tuition = num;
double sum = 0.0;
//我从第⼗⼀年开始算的
num += num*0.05;
for(int i = 0; i < 4; ++i){
sum += num;
num += num*0.05;
}
System.out.println(tuition);
System.out.println(sum);
}
schedule怎么读音发音}
8
import java.util.Scanner;
linux快速删除几十万个文件public class Main{
public static void main(String[] args){
System.out.println("Enter information about ten students"); String[] name = new String[10];
double[] score = new double[10];
Scanner input = new Scanner(System.in);
for(int i = 0; i < 10; ++i){
name[i] = ();
score[i] = Double();
}
for(int i = 0; i < 10; ++i){
System.out.println(name[i] + ":" + score[i]);
}
}
}
9
import java.util.Scanner;
public class Main{
public static void main(String[] args){
System.out.println("Enter information about ten students"); String[] name = new String[10];
double[] score = new double[10];
Scanner input = new Scanner(System.in);
字符串拼接java
for(int i = 0; i < 10; ++i){
name[i] = ();
score[i] = Double();
}
double max;
int temp = 0;
//选择排序法
for(int i = 0; i < 9; ++i){
max = score[i];
temp = i;
for(int j = i + 1; j < 10; ++j){
if(score[j] > max){
max = score[j];
temp = j;
}
}
double tp = score[i];
score[i] = score[temp];
score[temp] = tp;
String tstr = name[i];
name[i] = name[temp];
name[temp] = tstr;
}
for(int i = 0; i < 2; ++i)
System.out.println(name[i] + " : " +score[i]); }
}
10
import java.util.Scanner;
public class Main{
public static void main(String[] args){
int num = 0;
java经典上机编程题
for(int i = 1; i <= 1000; ++i){
if(i%5 == 0 && i%6 == 0){
System.out.print(i + " ");
++num;
if(num%10 == 0)
System.out.println();
}
}
}
}
11
import java.util.Scanner;
public class Main{
public static void main(String[] args){
int num = 0;
for(int i = 1; i <= 1000; ++i){
if(i%5 == 0 ^ i%6 == 0){
System.out.print(i + " ");
++num;
if(num%10 == 0)
System.out.println();
}
}

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。