標題:
TQC+ 103 計算平均值
[打印本頁]
作者:
周政輝
時間:
2016-12-10 11:11
標題:
TQC+ 103 計算平均值
[attach]1815[/attach]
作者:
王彥甯
時間:
2016-12-10 11:11
import java.text.DecimalFormat;
import java.util.Scanner;
public class JPA01 {
public static void main(String args[]){
System.out.println("Please input:");
Scanner scanner = new Scanner(System.in);
float x = scanner.nextInt();
float y = scanner.nextInt();
float z = scanner.nextInt();
float Average = (x+y+z)/3;
DecimalFormat df = new DecimalFormat("#.##");
String AVG = df.format(Average);
System.out.print("Average:"+AVG);
}
}
複製代碼
作者:
蔡庭豪
時間:
2016-12-10 11:12
import java.text.DecimalFormat;
import java.util.Scanner;
public class JPA01 {
public static void main (String args[]){
Scanner scanner =new Scanner(System.in);
System.out.println("Please input");
int x =scanner.nextInt();
int y =scanner.nextInt();
int z =scanner.nextInt();
float total = (float)(x+y+z)/3;
DecimalFormat df =new DecimalFormat("#.##");
String t = df.format(total);
System.out.println("Average:"+total);
}
}
複製代碼
作者:
張健勳
時間:
2016-12-10 11:13
import java.math.BigDecimal;
import java.util.Scanner;
public class JPA01 {
public static void main (String args[]){
System.out.println("Please input:");
Scanner scanner = new Scanner(System.in);
float num1 = scanner.nextInt();
float num2 = scanner.nextInt();
float num3 = scanner.nextInt();
float Average;
Average = ( num1 + num2 + num3 )/3;
double ft = Average;
int scale = 2;
int roundingMode = 4;
BigDecimal bd = new BigDecimal((double)ft);
bd = bd.setScale(scale,roundingMode);
ft = bd.floatValue();
System.out.print("Average : "+ft);
}
}
複製代碼
作者:
蔡季樺
時間:
2016-12-16 18:42
import java.util.Scanner;
public class JPA01 {
public static void main(String args[])
{
Scanner scanner = new Scanner(System.in);
int x = scanner.nextInt();
int y = scanner.nextInt();
int z = scanner.nextInt();
float total = x+y+z;
System.out.println(total/3);
}
}
複製代碼
作者:
謝瀞儀
時間:
2016-12-16 21:19
import java.util.Scanner;
public class JPA01
{
public static void main(String[] args)
{
System.out.println("Please input:");
Scanner s = new Scanner(System.in);
float x,y,z;
x = s.nextFloat();
y = s.nextFloat();
z = s.nextFloat();
System.out.printf("Average: %.2f",(x+y+z)/3);
}
}
複製代碼
歡迎光臨 種子論壇 | 高雄市資訊培育協會學員討論區 (http://seed.istak.org.tw/)
Powered by Discuz! 7.2