返回列表 發帖

資料輸入 (一)

運用套件 java.io 下的 Console 類別, 作字串輸入的練習.
  1. import java.io.Console;
  2. public class Ch05
  3. {
  4.     public static void main(String args[])
  5.     {
  6.          String str1,str2;
  7.          Console c=System.console();
  8.          System.out.print("輸入字串一: ");
  9.          str1=c.readLine();
  10.          System.out.println("字串一: "+str1);
  11.          System.out.print("輸入字串二: ");
  12.          str2=c.readLine();
  13.          System.out.println("字串二: "+str2);
  14.     }
  15. }
複製代碼

  1. import java.io.Console;
  2. public class J
  3. {
  4.     public static void main(String args[])
  5.     {
  6.          String str1,str2;
  7.          Console c=System.console();
  8.          System.out.print("輸入字串一:");
  9.          str1=c.readLine();
  10.          System.out.println("字串一:"+str1);
  11.          System.out.print("輸入字串二:");
  12.          str2=c.readLine();
  13.          System.out.println("字串二:"+str2);
  14.     }
  15. }
複製代碼

TOP

  1. import java.io.Console;
  2. public class Ch01
  3. {
  4.     public static void main(String args[])
  5.     {
  6.          String str1,str2;
  7.          Console c=System.console();
  8.          System.out.print("請輸入字串一:");
  9.          str1=c.readLine();
  10.          System.out.println("字串一:"+str1);
  11.          System.out.print("請輸入字串二:");
  12.          str2=c.readLine();
  13.          System.out.println("字串二:"+str2);
  14.     }
  15. }
複製代碼

TOP

  1. import java.io.Console;
  2. public class king{
  3.       public static void main(String []args)
  4.       {
  5.         Console  c=System.console();
  6.         String queen prince;
  7.         System.out.print("輸入一段字串: ");
  8.         queen=c.readLine();
  9.         System.out.print("字串1:"+queen);
  10.         
  11.         System.out.print("輸入另一段字串: ");
  12.         prince=c.readLine();
  13.         System.out.print("字串2:"+prince);


  14.       }
複製代碼

TOP

  1. import java.io.Console;
  2. public class Ch02
  3. {
  4.   public static void main (String args[] )
  5.   {
  6.     String str11,str22;
  7.     Console c=System.console();
  8.     System.out.print("輸入字串1:");
  9.     str11=c.readLine();
  10.     System.out.println("字串1:"+str11);
  11.     System.out.print("輸入字串2: ");
  12.     str22=c.readLine();
  13.     System.out.println("字串2:"+str22);

  14.   }


  15. }
複製代碼

TOP

返回列表