在C double / float中有一个设置类型说明符:%f
%F
%g
%G
%e
%E
。
%f
和%F
,%g
和%G
,%e
和%E
?根据printf
和scanf
,输出相等。那么为什么大写和小写都有效?
请注意,scanf double的类型说明符以小写l
答案 0 :(得分:2)
%f
和%F
之间的区别在于它们是否打印无穷大而NaN是小写还是大写。这是一个例子:
#include <stdio.h>
#include <math.h>
int main(){
printf("%f and %f\n", INFINITY, nan("0")); //Prints "inf and nan"
printf("%F and %F\n", INFINITY, nan("0")); //Prints "INF and NAN"
return 0;
}
打印实数时, %f
和%F
相同。例如,printf("%f", 1.0)
和printf("%F", 1.0)
完全相同。
请注意,%F
仅适用于C99或C ++。
%e
和%E
之间的区别在于&#34; e&#34;将数字和指数分开的是大写或小写(例如1.0e+0
或1.0E+0
。对于无穷大和楠也有区别,就像%f
和%F
一样这是一个例子:
#include <stdio.h>
#include <math.h>
int main(){
printf("%e, %e and %e\n", INFINITY, nan("0"), 1.0); //Prints "inf, nan and 1.0000e+00"
printf("%E, %E and %E\n", INFINITY, nan("0"), 1.0); //Prints "INF, NAN and 1.0000E+00"
return 0;
}
%g
和%G
之间的区别在于%g
在%e
和%f
之间的最短时间,%G
在%E
和%F
之间的距离最短var allowedLetters = ["A","B","C","D","E","F","G","H"];
var i = Math.round(Math.random() * (allowedLetters.length - 1));
var letter = allowedLetters[i];
console.log(letter)
和 private String userID;
private FirebaseDatabase mFirebaseDatabase;
private FirebaseAuth mAuth;
private FirebaseAuth.AuthStateListener mAuthListener;
private DatabaseReference myRef;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_home);
//Authenticate user
mAuth = FirebaseAuth.getInstance();
mFirebaseDatabase = FirebaseDatabase.getInstance();
myRef = mFirebaseDatabase.getReference();
FirebaseUser user = mAuth.getCurrentUser();
if(mAuth.getCurrentUser() == null){
finish();
startActivity(new Intent(this, MainActivity.class));
}
userID = user.getUid();
public void onDataChange(DataSnapshot dataSnapshot) {
ArrayList<CharSequence> array = new ArrayList<>(Arrays.asList(HomeActivity.this.getResources().getTextArray(R.array.array)));
map = (Map<String, Object>) dataSnapshot.child("users").child(userID).getValue();
int x = 16;
for (Map.Entry<String, Object> entry : map.entrySet()) {
String key = entry.getKey();
array.add(x, key);
x++;
}
。
答案 1 :(得分:0)
specifier Output Example
d or i Signed decimal integer 392
u Unsigned decimal integer 7235
o Unsigned octal 610
x Unsigned hexadecimal integer 7fa
X Unsigned hexadecimal integer (uppercase) 7FA
f Decimal floating point, lowercase 392.65
F Decimal floating point, uppercase 392.65
e Scientific notation (mantissa/exponent), lowercase 3.9265e+2
E Scientific notation (mantissa/exponent), uppercase 3.9265E+2
g Use the shortest representation: %e or %f 392.65
G Use the shortest representation: %E or %F 392.65
a Hexadecimal floating point, lowercase -0xc.90fep-2
A Hexadecimal floating point, uppercase -0XC.90FEP-2
c Character a
s String of characters sample
p Pointer address b8000000
n Nothing printed.
The corresponding argument must be a pointer to a signed int.
The number of characters written so far is stored in the pointed location.
% A % followed by another % character will write a single % to the stream. %