#include <stdio.h>
int main()
{
typedef union{
int a ;
char c;
float f;
} myu;
myu sam;
sam.a = 10;
sam.f=(float)5.99;
sam.c= 'H';
printf("%d\n %c\n %f\n",sam.a,sam.c,sam.f);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
输出
1086303816
H
5.990025
为什么整数的值变化如此之大,而浮点数却几乎相同。
试图打印这种模式
*
***
*****
*******
Run Code Online (Sandbox Code Playgroud)
for和while循环在某种程度上不能以正确的方式工作.这个逻辑有什么问题吗?
public class Test {
public static void main(String args[]) {
for (int i = 1; i >= 4; i++) {
for (int j = 1; j <= 7; j++) {
while (i + j >= 5 && (Math.abs(j - i)) <= 3) {
System.out.print("*");
}
System.out.print(" ");
}
System.out.println();
}
}
Run Code Online (Sandbox Code Playgroud)