Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static void main(String[] args) {
- //I print an array with letters from A-Z
- char abc[]=new char[26];
- for(int i=0; i<abc.length; i++) {
- abc[i]=(char)('A'+i);
- System.out.println(abc[i]);
- }
- //I ask for positions and save the results in a String
- do {
- String result="";
- Scanner sn = new Scanner(System.in);
- int num=sn.nextInt();
- result=result + abc[num];
- }while(num!=-1);
- }
- }
- while(true) {
- int num=sn.nextInt();
- if(num == -1) {
- break;
- }
- //Do stuff
- int num=sn.nextInt();
- //When user inputs -1 to quit num= -1
- result=result + abc[num];
- //This will call the -1 index of abc
- while(true) {
- try { //Add a try catch to prevent InputMisMatchException
- num=sn.nextInt();
- }catch(Exception e) {
- e.printStackTrace();
- }
- if(num < 0 || num > 25) { //If it is going to be out of bounds
- break;
- }
- if(num>=0) {
- result+=abc[num];
- }
- }
- System.out.println(result);
- public static void main(String[] args) {
- //I print an array with letters from A-Z
- char abc[]=new char[26];
- for(int i=0; i<abc.length; i++) {
- abc[i]=(char)('A'+i);
- System.out.println(abc[i]);
- }
- //I ask for positions and save the results in a String
- Scanner sn = new Scanner(System.in);
- int num;
- String result = "";
- while(num = sn.nextInt() != -1) {
- result = result + abc[num];
- }
- System.out.println(result);
- }
- Scanner sn = new Scanner(System.in);
- int num;
- String result = "";
- while(true) {
- num=sn.nextInt();
- if(num == -1) {
- break;
- }
- if(num>=0) {
- result+=abc[num];
- }
- }
- System.out.println(result);
Add Comment
Please, Sign In to add comment