标签:eof 就是 9.png visual while port 1.2 第一章 ret
a. ( 0 + 15 ) / 2
b. 2.0e-6 * 100000000.1
c. true && false || true && true
答案:a.7(类型是整型,所以输出为7)
b.200.0000002 (
2.0e-6 表示 2.0*10的-6次方,为 0.000002
0.000002 * 100000000.1 = 200.0000002
)
c.ture
a. (1 + 2.236)/2
b. 1 + 2 + 3 + 4.0
c. 4.1 >= 4
d. 1 + 2 + "3"
答案:a.1.618(浮点型) b. 10.0 c.true d.33
答案:java代码,这里了解了“==”与“equals”的区别。https://mp.weixin.qq.com/s/pfLGs6x-_-YbPist1nTkUQ
import java.util.Scanner;
public class E {
public static void main(String[] args) {
System.out.println("请输入三个整数");
Scanner scanner1 = new Scanner(System.in);
String string1 = scanner1.next();
Scanner scanner2 = new Scanner(System.in);
String string2 = scanner2.next();
Scanner scanner3 = new Scanner(System.in);
String string3 = scanner3.next();
Integer number1 = Integer.valueOf(string1);
Integer number2 = Integer.valueOf(string2);
Integer number3 = Integer.valueOf(string3);
if(number1 .equals(number2) && number1 .equals(number3) && number2 .equals(number3)) {
System.out.println("equal");
} else {
System.out.println("not equal");
}
}
}
a. if (a > b) then c = 0;
b. if a > b { c = 0; }
c. if (a > b) c = 0;
d. if (a > b) c = 0 else b = 0;
答案:a.java中没有then关键字,Visual Basic中有
b.a>b缺少()
c.正确
d.c=0缺少;(分号)
import java.util.Scanner;
public class E {
public static void main(String[] args) {
System.out.println("请输入两个数字");
Scanner scanner1 = new Scanner(System.in);
String string1 = scanner1.next();
Scanner scanner2 = new Scanner(System.in);
String string2 = scanner2.next();
double x=Double.valueOf(string1);
double y=Double.valueOf(string2);
if(x>=0&&x<=1&&y>=0&&y<=1)
System.out.println(true);
else
System.out.println(false);
}
}
int f = 0;
int g = 1;
for (int i = 0; i <= 15; i++)
{
StdOut.println(f);
f = f + g;
g = f - g;
}
答案:一段斐波那契数列。
0
1
1
2
3
5
8
13
21
34
55
89
144
233
377
610
//a.
double t = 9.0;
while (Math.abs(t - 9.0/t) > .001)
t = (9.0/t + t) / 2.0;
StdOut.printf("%.5f\n", t);
//b.
int sum = 0;
for (int i = 1; i < 1000; i++)
for (int j = 0; j < i; j++)
sum++;
StdOut.println(sum);
//c.
int sum = 0;
for (int i = 1; i < 1000; i *= 2)
for (int j = 0; j < 1000; j++)
sum++;
StdOut.println(sum);
答案:a.3.00009 b.499500((999+1)*999/2) c.10000
a. System.out.println(‘b‘);
b. System.out.println(‘b‘ + ‘c‘);
c. System.out.println((char) (‘a‘ + 4));
答案:a.b b.197 c.e (b的ASCII码为98,c的为99)
String s = "";
for (int n = N; n > 0; n /= 2)
s = (n % 2) + s;
答案:
public static String decimalToBinary(int n) {
String resultString = "";
for (int i = 31; i >= 0; i--)
resultString = resultString + (n >>> i & 1);
return resultString;
}
int[] a;
for (int i = 0; i < 10; i++)
a[i] = i * i;
答案:它没有用 new 为 a[] 分配内存,这段代码会产生一个 variable a might not have been initialized 的编译错误。
答案:
private static void printout(boolean[][] a1){
for (int i = 0; i < a1.length; i++) {
for (int j = 0; j < a1[i].length; j++) {
if (a1[i][j]){
System.out.println(String.format(Locale.CHINA,"%d %d *",i+1,j+1));
} else {
System.out.println(String.format(Locale.CHINA,"%d %d /",i+1,j+1));
}
}
}
}
int[] a = new int[10];
for (int i = 0; i < 10; i++)
a[i] = 9 - i;
for (int i = 0; i < 10; i++)
a[i] = a[a[i]];
for (int i = 0; i < 10; i++)
System.out.println(a[i]);//如书中所示打印i,则题目无意义
答案:
答案:
int[ ][ ] a={{1,2,3},{4,5,6}};
int[][] temp = new int[a[0].length][a.length];
for (int i = 0; i < a[0].length; i++) {
for (int j = 0; j < a.length; j++) {
temp[i][j] = a[j][i];
System.out.print(temp[i][j] + " ");
if(j == a.length - 1)
System.out.print("\n");
}
}
答案:
public static int lg(int N){
// m = log a N
int a=2; //a为底数
int m=0;
for(;N>1;N/=a){
m++;
}
return m;
}
标签:eof 就是 9.png visual while port 1.2 第一章 ret
原文地址:https://www.cnblogs.com/RedCoral/p/8953579.html