重慶分公司,新征程啟航
為企業提供網站建設、域名注冊、服務器等服務
為企業提供網站建設、域名注冊、服務器等服務
public static void main(String[] args) {
創新互聯建站專注于南昌縣企業網站建設,響應式網站建設,商城網站開發。南昌縣網站建設公司,為南昌縣等地區提供建站服務。全流程按需求定制開發,專業設計,全程項目跟蹤,創新互聯建站專業和態度為您提供的服務
Scanner sca = new Scanner(System.in);
System.out.println("輸入美元數");
int dollars = sca.nextInt();
System.out.println("輸入美分數");
int cents = sca.nextInt();
int all = dollars * 100 + cents;
System.out.println(all / 100 + "dollars" + all % 100 / 25 + "quarter"
+ all % 25 / 10 + "dimes" + all % 10 / 5 + "nickets" + all % 5
+ "cents");
}
程序:
import java.io.*; import java.awt.*; import java.awt.event.*; import javax.swing.*; class test8{ public static void main(String[] args) { JFrame f=new JFrame(); f.setSize(200, 200); JTextArea t1 = new JTextArea(1,5); JTextArea t2 = new JTextArea(1,5); JButton b1=new JButton("test it"); Label l1,l2; l1 = new Label(); l2 = new Label(); l1.setText("Please Enter The Number"); l2.setText("The Result Of The Test"); Choice c = new Choice(); c.add("RMB"); c.add("KRW"); c.add("DOLLAR"); Choice c1 = new Choice(); c1.add("RMB"); c1.add("KRW"); c1.add("DOLLAR"); f.add(l1); f.add(t1); f.add(c); f.add(l2); f.add(t2); f.add(c1); f.add(b1); b1.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) {if(c.getSelectedItem()=="RMB"c1.getSelectedItem()=="DOLLAR") {String s; s=t1.getText(); int q=0; q=Integer.parseInt(s); double w; w=q*0.1452; String r = Double.toString(w); t2.setText(r); } else if(c.getSelectedItem()=="DOLLAR"c1.getSelectedItem()=="RMB") {String s; s=t1.getText(); int q=0; q=Integer.parseInt(s); double w; w=q*6.8866; String r = Double.toString(w); t2.setText(r); } else if(c.getSelectedItem()=="RMB"c1.getSelectedItem()=="KRW") {String s; s=t1.getText(); int q=0; q=Integer.parseInt(s); double w; w=q*164.9824; String r = Double.toString(w); t2.setText(r); } else if(c.getSelectedItem()=="KRW"c1.getSelectedItem()=="RMB") {String s; s=t1.getText(); int q=0; q=Integer.parseInt(s); double w; w=q*0.0061; String r = Double.toString(w); t2.setText(r); } else if(c.getSelectedItem()=="DOLLAR"c1.getSelectedItem()=="KRW") {String s; s=t1.getText(); int q=0; q=Integer.parseInt(s); double w; w=q*1136.2500; String r = Double.toString(w); t2.setText(r); } else if(c.getSelectedItem()=="KRW"c1.getSelectedItem()=="DOLLAR") {String s; s=t1.getText(); int q=0; q=Integer.parseInt(s); double w; w=q*0.0009; String r = Double.toString(w); t2.setText(r); } } } ); f.setLayout(new FlowLayout()); f.setVisible(true); f.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } }); } }
操作環境:java 版型號:8.64
拓展資料:
1、Java是一門面向對象編程語言,不僅吸收了C++語言的各種優點,還摒棄了C++里難以理解的多繼承、指針等概念,因此Java語言具有功能強大和簡單易用兩個特征。Java語言作為靜態面向對象編程語言的代表,極好地實現了面向對象理論,允許程序員以優雅的思維方式進行復雜的編程。 Java具有簡單性、面向對象、分布式、健壯性、安全性、平臺獨立與可移植性、多線程、動態性等特點。Java可以編寫桌面應用程序、Web應用程序、分布式系統和嵌入式系統應用程序等
2、由于C++所具有的優勢,該項目組的研究人員首先考慮采用C++來編寫程序。但對于硬件資源極其匱乏的單片式系統來說,C++程序過于復雜和龐大。另外由于消費電子產品所采用的嵌入式處理器芯片的種類繁雜,如何讓編寫的程序跨平臺運行也是個難題。為了解決困難,他們首先著眼于語言的開發,假設了一種結構簡單、符合嵌入式應用需要的硬件平臺體系結構并為其制定了相應的規范,其中就定義了這種硬件平臺的二進制機器碼指令系統(即后來成為“字節碼”的指令系統),以待語言開發成功后,能有半導體芯片生產商開發和生產這種硬件平臺。對于新語言的設計,Sun公司研發人員并沒有開發一種全新的語言,而是根據嵌入式軟件的要求,對C++進行了改造,去除了留在C++的一些不太實用及影響安全的成分,并結合嵌入式系統的實時性要求,開發了一種稱為Oak的面向對象語言。
操作環境:java 版型號:8.64
操作環境:C++ 版型號:8.2.64
因為我們用的都是中文環境(默認),所以你的程序只能輸入中國的貨幣符號,要通過Locale類的: public static void setDefault(Locale newLocale)方法設置下語言環境
具體代碼可參考如下的:
import java.util.Currency;
import java.util.Locale;
import java.util.Scanner;
/**
*
* @author top
*/
public class CurrencySymbol {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
System.out.println("Please input a valid ISO 4217 currency code: ");
Scanner scan = new Scanner(System.in);
String code1 = scan.nextLine();
Locale.setDefault(Locale.CHINA);//中文語言環境下
Currency currency1 = Currency.getInstance(code1);
System.out.println(currency1.getSymbol());
String code2 = scan.nextLine();
Locale.setDefault(Locale.US);//美國
Currency currency2 = Currency.getInstance(code2);
System.out.println(currency2.getSymbol());
}
}
輸入一個美圓數字?然后輸出等值的人民幣?
假設一美圓兌換7.5人民幣~
public class A
{
public static void main(String[] args)
{
System.out.println("請輸入,只能是數字!");
String serial = inputString();
System.out.println(Long.parseLong(serial)*7.5)
}
private static String inputString()
{
BufferedReader bufferedreader = new BufferedReader(
new InputStreamReader(System.in));
String s = null;
try
{
s = bufferedreader.readLine();
}
catch (IOException ioexception)
{
ioexception.printStackTrace();
}
return s;
}
}