重生异界我用java打造商业帝国
生活随笔
收集整理的這篇文章主要介紹了
重生异界我用java打造商业帝国
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
一、計算牛奶中蛋白質(zhì)的總量
?代碼:
import java.util.Scanner;public class Milk { public static void main(String[] args) { // TODO Auto-generated method stubScanner sc = new Scanner(System.in);//創(chuàng)造掃描器,獲取控制臺輸入的值System.out.println("請輸入牛奶盒數(shù)(a): ");//輸出提示float a = sc.nextFloat();//記錄數(shù)據(jù)的第一個數(shù)字float b = 6.4F;//把浮點型6.4賦值給bSystem.out.println("24袋牛奶含有的蛋白質(zhì):"+(a*b));//輸出計算積sc.close();//關(guān)閉掃描器}}?二:輸出肯德基一天售出漢堡的數(shù)量及金額
?代碼:
import java.util.Scanner;public class Hamburger { public static void main(String[] args) { // TODO Auto-generated method stubScanner sc = new Scanner(System.in);//創(chuàng)建掃描器,獲取控制臺輸入的值System.out.println("請輸入購買漢堡包的個數(shù)(g): ");//輸出提示float g = sc.nextFloat();//記錄數(shù)據(jù)的第一個數(shù)字float h = 15.5F;//把浮點型15.5賦值給hSystem.out.println("全天售出的總金額為:"+(g*h));//輸出計算積sc.close();//關(guān)閉掃描器}}三:將高鐵速度km/h轉(zhuǎn)換為m/s
?代碼:
import java.util.Scanner;public class Hsr { public static void main(String[] args) { // TODO Auto-generated method stubSystem.out.println("請輸入高鐵速度:");//輸出請輸入高鐵速度:Scanner scanner=new Scanner(System.in);//從鍵盤獲取輸入的值int s=scanner.nextInt();//把scanner賦值給sSystem.out.println(s+"km/h"+"="+(int)(s/3.6)+"m/s");//輸出s的值}}?
?四:地鐵購票金額計算
?代碼:
iimport java.util.Scanner;public class Ditiegoupiaojingejisuan { public static void main(String[] args) { // TODO Auto-generated method stubSystem.out.println("購票信息");//輸出購票信息System.out.println("-----------");//輸出----------System.out.println("目的車站:人民廣場");//輸出目的車站:人民廣場System.out.println("票價:2.00");//輸出票價:2.00System.out.println("購票數(shù)量:");//輸出購票數(shù)量:Scanner scanner=new Scanner(System.in);//從鍵盤獲取輸入的值int w=scanner.nextInt();//把scanner賦值給wint q=2;//將票價賦值給qSystem.out.println("應(yīng)付金額:"+q*w);//輸出應(yīng)付金額System.out.println("已付金額");//輸出已付金額Scanner piao =new Scanner(System.in);//從鍵盤獲取輸入的值int r=scanner.nextInt();//把scanner賦值給rSystem.out.println("找零:"+(r-q*w));//輸出找零:}}總結(jié)
以上是生活随笔為你收集整理的重生异界我用java打造商业帝国的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: React几种传递参数的方法
- 下一篇: 指令集的概念