0
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();
    }
}

i want to change while to do~while and while to for. i tried it but i don't know how to change the if part.

Hellmud
  • 49
  • 5

2 Answers2

0

your question isn't exactly clear, but maybe this is what you had in mind :

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();
    }
}
Alon Gadot
  • 555
  • 3
  • 10
0

Do- while loop is there in 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);
Abhishek
  • 688
  • 6
  • 21