小编Nic*_*Dry的帖子

为什么我的java程序不接受用户的字母输入?

编辑:我的问题已经部分修复.现在我可以输入文本,但输入'shiphalf'值后没有任何内容.我是否错误地构造了if else语句?


我试图让人们输入优惠券代码,但我无法弄清楚如何让控制台知道用户正在输入文本.我觉得错误在这里的某个地方:

        System.out.println("Enter a Coupon Code: ");
        String ship = input.nextLine(); 
Run Code Online (Sandbox Code Playgroud)

但我不完全确定.以下是完整的源代码:

package pseudoPackage;

import java.util.Scanner;

public class PseudoCode {

    public static void main(String[] args) {


        Scanner input = new Scanner(System.in);


        int ship1 = 0;
        int ship2 = 6;
        int ship3 = 2;
        String shiphalf = null;

        System.out.print("How much will shipping cost you?");
        System.out.println();
        System.out.print("Enter your textbook cost in dollars without the $: ");
        double cost = input.nextDouble();



        if ( cost >= 100 ) {
            System.out.println("Your shipping costs …
Run Code Online (Sandbox Code Playgroud)

java

3
推荐指数
1
解决办法
192
查看次数

标签 统计

java ×1