int a=45; int b =102; double c = (double)a/b*100; String str = c + "%"; System.out.println(str);
lanseqingxu(蓝色情绪) ::不行呀,为什么结果是Infinity% ??????
我的代码在jdk1.5下编译无误,而明月的输出结果为0 大家用的jdk版本是什么?
楼上的已经是正确的了,只是补充一下, int a=45; int b=102; double d=((double)a/b)*100; NumberFormat nf= new DecimalFormat("#.00");//可以定义数据的格式为保留两位小数 System.out.println(nf.format(d)+"%");
绝对可以,这么简单的东西啊!!!public class ss { public static void main(String[] args){ int a=45; int b =102; double c = (double)a/b*100; String str = c + "%"; System.out.println(str); }}
import java.text.*;public class ss { public static void main(String[] args){ int a=45; int b =102; double c = (double)a/b*100; double d = ((double)a/b)*100; String str = "c=" + c + "%"; NumberFormat nf= new DecimalFormat( "#.00" );//可以定义数据的格式为保留两位小数 System.out.println( str ); System.out.println( "d=" + nf.format(d) + "%" );
int b =102;
double c = (double)a/b*100;
String str = c + "%";
System.out.println(str);
大家用的jdk版本是什么?
int a=45;
int b=102;
double d=((double)a/b)*100;
NumberFormat nf= new DecimalFormat("#.00");//可以定义数据的格式为保留两位小数
System.out.println(nf.format(d)+"%");
public static void main(String[] args){
int a=45;
int b =102;
double c = (double)a/b*100;
String str = c + "%";
System.out.println(str);
}}
public static void main(String[] args){
int a=45;
int b =102;
double c = (double)a/b*100;
double d = ((double)a/b)*100;
String str = "c=" + c + "%";
NumberFormat nf= new DecimalFormat( "#.00" );//可以定义数据的格式为保留两位小数
System.out.println( str );
System.out.println( "d=" + nf.format(d) + "%" );
}}d=44.12%
c=44.11764705882353%
可以通过的。你是什么提示错误啊