標題:
304--餐點費用
[打印本頁]
作者:
許承鴻
時間:
2018-7-10 18:35
標題:
304--餐點費用
import java.util.Scanner;
public class JPD03 {
public static void main(String[] args) {
int total = 0;
int s = 0;
int count = 0;
double average;
System.out.print("Please enter meal dollars or enter -1 to stop: ");
...
}
System.out.println("餐點總費用:"________);
System.out.printf(" %d 道餐點平均費用為: %.2f %n"____________);
}
}
作者:
巫沛庭
時間:
2018-7-10 20:04
import java.util.Scanner;
public class JPA03
{
static Scanner num=new Scanner(System.in);
public static void main(String[] args) {
int total = 0;
int s = 0;
int count = 0;
double average;
while(true)
{
System.out.print("Please enter meal dollars or enter -1 to stop: ");
s=num.nextInt();
if(s==-1)
{
break;
}
total+=s;
count++;
}
average=total/count;
System.out.printf("餐點總費用:",total);
System.out.printf(" %d 道餐點平均費用為: %.2f %n",average);
}
}
複製代碼
作者:
張閎鈞
時間:
2018-7-10 20:10
import java.util.Scanner;
public class hi87 {
public static void main(String[] args) {
// TODO 自動產生的方法 Stub
Scanner k = new Scanner(System.in);
int a=0;
int b=0;
int c=0;
double average;
while(true)
{
System.out.print("Please enter meal dollars or enter -1 to stop: ");
a=k.nextInt();
if(a==-1)
{
break;
}
else
{
b=b+a;
c++;
}
}
average=b/c;
System.out.println("餐點總費用:"+b);
System.out.printf(" %d 道餐點平均費用為: %.2f \n",c,average);
}
}
複製代碼
歡迎光臨 種子論壇 | 高雄市資訊培育協會學員討論區 (http://seed.istak.org.tw/)
Powered by Discuz! 7.2