java - Print output on the same line -


i'm making translator in java translate fake language came fun. input english word , returns it's equivalent word in other language. it's translating everything, each new word on separate line , want output on 1 line. i'm still new java here code:

import java.io.*; import java.util.*;  public class translator {      private static scanner scan;      public static void main(string[] args) {              hashmap <string, string> xanthiumlang = new hashmap <string, string>();             xanthiumlang.put("hello", "fohran");             xanthiumlang.put("the", "krif");             xanthiumlang.put("of", "ney");             xanthiumlang.put("to", "dov");             xanthiumlang.put("and", "ahrk");              scanner scan = new scanner(system.in);             string sentence = scan.nextline();             string[] result = sentence.split(" ");             for(int = 0; < result.length; i++){             if(xanthiumlang.containskey(result[i])){                 result[i] = xanthiumlang.get(result[i]);                    }                  system.out.println(result[i]);                }         }  } 

i have few words in code of right , stored in hashmap. anyways said output of each word on separate line, not on 1 line. ideas or changes code helpful!

use system.out.print();. doing print entire array on 1 line. system.out.println(); print result on new line each time (hence ln @ end).

import java.io.*; import java.util.*;  public class translator {    private static scanner scan;    public static void main(string[] args) {      hashmap <string, string> xanthiumlang = new hashmap <string, string>();     xanthiumlang.put("hello", "fohran");     xanthiumlang.put("the", "krif");     xanthiumlang.put("of", "ney");     xanthiumlang.put("to", "dov");     xanthiumlang.put("and", "ahrk");      scanner scan = new scanner(system.in);     string sentence = scan.nextline();     string[] result = sentence.split(" ");       for(int = 0; < result.length; i++){          if(xanthiumlang.containskey(result[i])){            result[i] = xanthiumlang.get(result[i]);          }          system.out.print(result[i]);        }      }    } 

more on different formats here.


Comments

Popular posts from this blog

qt - Using float or double for own QML classes -

Create Outlook appointment via C# .Net -

ios - Swift Array Resetting Itself -