想要改变ASCII同时做~at和for

时间:2018-04-09 13:52:50

标签: java

import java.util.Scanner;

public class ASCII {
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);

        String s;
        char c;

        while(true){
            System.out.println("insert letters. (insert # exit)");
            s = scan.next();
            c = s.charAt(0);
            if(c == '#')
                break;
            System.out.print(c + " ASCII code " + (int)c + "end");
        }
        scan.close();
    }
}

我想改变的同时做〜            而且为了。  我尝试过,但我不知道如何更改if部分。

2 个答案:

答案 0 :(得分:0)

你的问题并不完全清楚,但也许这就是你的想法:

public class Program {

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);

        String s;
        char c;
        do {
            System.out.println("insert letters. (insert # exit)");
            s = scan.next();
            c = s.charAt(0);
            System.out.print(c + " ASCII code " + (int)c + " end \n");
        } while(c != '#');
        scan.close();
    }
}

答案 1 :(得分:0)

Do- while循环存在于Java中:

do{
            System.out.println("insert letters. (insert # exit)");
            s = scan.next();
            c = s.charAt(0);
            if(c == '#')
                break;
            System.out.print(c + " ASCII code " + (int)c + "end");
        }while(true);