提示用户选择笔颜色不起作用

时间:2017-11-16 03:36:45

标签: java

我应该提示用户根据我选择的笔颜色选择笔颜色。我已经包含了if,else if else else stamtement plus和.equalsignorecase,但每当我运行该文件时,它都不会让我输入任何东西?

(另外我的变量"颜色"如果有帮助,则定义为字符串。)

编辑:我已经在我的代码中嵌入了一个扫描程序类。它' S:

let headers = [
    "Authorization": "Basic xxxxxxxxxxxx"
]
let parameters = [

]

Alamofire.request(.POST, "url", parameters: parameters, headers: headers, encoding: .JSON)
        .validate(contentType: ["application/json"])
        .responseJSON { response in
            if response.response?.statusCode == 200 {
                print("Success with JSON: \(response.result.value)")

                success(updatedUser)
            }
            else {
                let error = response.result.value as! NSDictionary
                let errorMessage = error.objectForKey("message") as! String
                print(errorMessage)
                failure(errorMessage)
            }


    }

因此我的任何代码都有"很酷"它是我给我的扫描仪的名字。

Scanner cool=new Scanner(system.in)

2 个答案:

答案 0 :(得分:0)

您需要Scanner来阅读输入。试试这个。

public class Test {

    public static void main(String[] args) {
        Scanner reader = new Scanner(System.in); // Reading from System.in
        System.out.println(
                "Please enter the color that you wish to use to draw your point(color options: Red, blue, light blue, pink, green, orange, magenta, and yellow):");
        String color = reader.nextLine(); // Scans the next token of the input as an string.

        System.out.println(color);
        // once finished
        reader.close();

    }

}

答案 1 :(得分:0)

根据您的问题,您应该想要显示您输入的内容。以下是一些相关的输入过程:

您可以根据要求使用以下任何选项。

  

扫描仪课程

import java.util.Scanner; 
Scanner scan = new Scanner(System.in);
String s = scan.next();
int i = scan.nextInt();
  

BufferedReader和InputStreamReader类

import java.io.BufferedReader;
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String s = br.readLine();
int i = Integer.parseInt(br.readLine());
  

DataInputStream类

import java.io.DataInputStream;
DataInputStream dis = new DataInputStream(System.in);
int i = dis.readInt();

不推荐使用DataInputStream类中的readLine方法。要获取String值,您应该使用以前的BufferedReader

解决方案
  

控制台类

import java.io.Console;
Console console = System.console();
String s = console.readLine();
int i = Integer.parseInt(console.readLine());

显然,这种方法在某些IDE中不能很好地工作。您可以通过System.out.println(input_object)打印/提示您输入的内容。