導航:首頁 > 編程語言 > java輸入字元

java輸入字元

發布時間:2022-02-06 19:59:13

java中如何輸入一個字元

import java.util.*;

public class Test_01

{

public static void main(String[] args)throws Exception

{

System.out.println("請輸入一個字元");

char c=(char)System.in.read();

System.out.println(c);

}

}

(1)java輸入字元擴展閱讀:

還可以輸入字元串,輸入字元串的方法

import java.io.*;

public class Test

{

public static void main(String[] args) throws IOException

{

BufferedReader buf = new BufferedReader (new InputStreamReader(System.in));

BufferedWriter buff = new BufferedWriter(new FileWriter("abc.txt"));

String str = buf.readLine();

while(!str.equals("exit"))

{

buff.write(str);

buff.newLine();

str = buf.readLine();

}

buf.close();

buff.close();

}

}

Ⅱ java中怎樣從鍵盤輸入一個字元然後輸出

import java.util.Scanner;
public class Main {
public static void main(String args[]){
Scanner scanner=new Scanner(System.in);
String s=scanner.next();
System.out.println(s);
}
}
這是輸出第一個單詞
如果只要字元的話將System.out.println(s);改為
System.out.println(s.charAt(0));

Ⅲ java如何輸入一個字元,

char c=sc.next().charAt(0);
charAt()是String對象的取字元方法,0是取第一位的

String x=sc.next();

char c=x.charAt(0);

Ⅳ 在java中如何輸入一個char型字元。

方法一:

Scanner cin=new Scanner(System.in);

String s=cin.nextLine();

char ans=s.charAt(0);

這樣即可獲取一個字元。

方法二:

byte[] b=new byte[2];

try{

System.in.read(b)

}catch(Exception e){}

char ans=new String(b).charAt(0);

這樣即可獲取一個字元

Ⅳ java中如何輸入一個字元

需要添加拋出聲明,但是可以從鍵盤輸入一個字元,如果輸入多個的話,那麼只會保存第一個字元。使用Scanner 類從鍵盤錄入一個字元,使用String 接收; 然後使用 String 的charAt功能。

Ⅵ JAVA中怎樣輸入字元串

1.首先,導入java.util.*包。

(6)java輸入字元擴展閱讀:

Java是一門面向對象編程語言,不僅吸收了C++語言的各種優點,還摒棄了C++里難以理解的多繼承、指針等概念,因此Java語言具有功能強大和簡單易用兩個特徵。Java語言作為靜態面向對象編程語言的代表,極好地實現了面向對象理論,允許程序員以優雅的思維方式進行復雜的編程 。

Java具有簡單性、面向對象、分布式、健壯性、安全性、平台獨立與可移植性、多線程、動態性等特點。

Java可以編寫桌面應用程序、Web應用程序、分布式系統和嵌入式系統應用程序等。

Ⅶ java中的字元輸入語句

樓上幾位說的沒錯,Scanner就很好用了。
Scanner scan=new Scanner(System.in);
int n=scan.nextInt();
long c=scan.nextLong();
不過沒有nextChar(),但可以輸入字元串,就是:
String s=scan.next();或者s=scan.nextLine();
兩者的區別是前面是讀到空格就返回,後面那個是讀入一行

Ⅷ 如何使用Java輸入一個字元

你的意思是不是想要像C語言中的scanf 和C++中的cin一樣輸入字元或數值?

try
{
BufferedReader bf=new BufferedReader(new InputStreamReader(System.in));
String s;
s=bf.readLine();
System.out.println(Integer.valueOf(s));
}
catch (Exception e)
{

}

Ⅸ java 輸入字元 輸出字元串

input.nextInt()是讀整形數據,用nextLine()讀取字元串的,

Ⅹ 在java中如何用鍵盤輸入一個數,字元,字元串

  1. 輸入一個數

    Scanner in=new Scanner(System.in); //使用Scanner類定義對象
    System.out.println("請輸入float型數據");
    float a=in.nextFloat(); //接收float型數據
    System.out.println(a);
    System.out.println("請輸入float型整形數據");
    int b=in.nextInt(); //接收整形數據
    System.out.println(b);

  2. 字元串

    BufferedReader buffer = new BufferedReader(new InputStreamReader(System.in));
    System.out.println("請輸入一串字元串");
    String text = buffer.readLine();
    System.out.println("您輸入的字元串是:" + text);

  3. 字元

    System.out.println("請輸入一字元");
    char c=(char)System.in.read();
    System.out.println(c);

閱讀全文

與java輸入字元相關的資料

熱點內容
二級加密圖 瀏覽:113
壓縮機異音影響製冷嗎 瀏覽:711
德斯蘭壓縮機 瀏覽:490
程序員太極拳視頻 瀏覽:531
網上購買加密鎖 瀏覽:825
安卓為什麼軟體要隱私 瀏覽:83
虛擬主機管理源碼 瀏覽:811
java圖形圖像 瀏覽:230
單片機輸出口電平 瀏覽:486
java配置資料庫連接 瀏覽:479
java多態的體現 瀏覽:554
java的split分隔符 瀏覽:128
跪著敲代碼的程序員 瀏覽:238
web和php有什麼區別 瀏覽:120
加密的電梯卡怎麼復制蘋果手機 瀏覽:218
warez壓縮 瀏覽:137
黑馬程序員培訓機構官網天津 瀏覽:904
mainjavasrc 瀏覽:59
如何買伺服器挖礦 瀏覽:292
php批量上傳文件夾 瀏覽:561