導航:首頁 > 編程語言 > 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輸入字元相關的資料

熱點內容
喝什麼茶能緩解壓抑 瀏覽:865
u命令無法打開 瀏覽:960
vue編譯後的js能爬嗎 瀏覽:453
解壓骰子推薦3代 瀏覽:749
安卓手機劃線密碼忘了怎麼解鎖 瀏覽:309
精美角度主圖指標源碼 瀏覽:278
程序員編程函數需要特別好嗎 瀏覽:181
fue加密毛發怎麼樣 瀏覽:929
網上考學歷app如何屏蔽 瀏覽:352
python矩陣庫 瀏覽:160
伺服器如何ping伺服器 瀏覽:281
雲伺服器雙機熱備怎麼做 瀏覽:98
安卓果盤高清帳號是什麼帳號 瀏覽:548
蘋果解激活鎖什麼叫伺服器解鎖 瀏覽:596
用海綿寶寶做解壓的東西 瀏覽:192
大pdf文件免費轉word 瀏覽:792
如何侵入ftp伺服器 瀏覽:192
智行app如何查詢學生票使用次數 瀏覽:736
程序員幾年後開始有前途 瀏覽:126
發微博伺服器數據異常什麼意思 瀏覽:233