0

How can I correct this ?

import java.util.Scanner; public class Char { ​public static void main (String args[]){ ​​int i,choice; ​​char digit1,digit2; do{ ​​Scanner scan=new Scanner(System.in); ​​System.out.print("Input a value: "); ​​digit1=scan.next().charAt(0); ​​System.out.print("Input another value: "); ​​digit2=scan.next().charAt(0); ​​ ​​​ ​​​System.out.print("The letter/s between " +digit1 +" and " +digit2 +" is " ); ​​​digit1++; ​​​ for(char ch=digit1;ch<digit2;++ch) ​​​ { ​​​​ System.out.print(ch); ​​​ } ​​​ ​​​System.out.print("\n Another[y/n]: "); ​​​choice=scan.next().charAt(0); ​​​ } ​​​while(choice=='y'); ​​​ Scanner scan=new Scanner(System.in); ​​​ ​​int ascii=(int) digit2; ​​ ​​if(digit2>=48 && digit2>=58 ) ​​{ ​​​System.out.println("Invalid Input! Please enter the same type of value"); ​​} ​​ ​​System.out.print("The number/s between " +digit1 +" and " +digit2 +" is " ); ​​for(i=digit1+1;i<digit2;i++) ​​{​ ​​​​System.out.print(i-'0');​ ​​​} ​​ ​​System.out.print("\n Another[y/n]: "); ​​choice=scan.next().charAt(0); ​​ ​​while(choice=='y'); ​​ ​​ ​ } ​ }

19th Aug 2019, 8:57 AM
alex pornela
alex pornela - avatar
1 ответ
0
there are ilegal chars ​​\u2039. In sololearn replace every pink spaces with normal spaces. second part of code needs rewrite, at the end you ask for y/n but there is no loop after. Because you have not do{ } there, while() after can end in infinity loop if answer is y (for yes) you can avoid it with comment this (about line 42) //while (choice == 'y');
19th Aug 2019, 10:38 AM
zemiak