java - How do you convert multiple lines of String input to Upper Case until EOF? -


import java.util.scanner;  public class shout {     public static void main(string[] args) {         string str1;         string str2 = "";          scanner keyboard = new scanner(system.in);          stringbuilder output = new stringbuilder();          while (keyboard.hasnextline()) {             str1 = keyboard.nextline();             stringbuilder sb = new stringbuilder(str1);             output.append(sb.touppercase().tostring()).append("\n");         }         system.out.print(output.tostring());     } } 

i looking convert multiple lines of input until eof (ctrl+d) uppercase. can used print out same multiple lines in uppercase? example, input , output like:

car bus taxi car bus taxi 

with repeated lines in uppercase.

put each line hashmap, , each time line check if same string found in hashmap. if not, print normal , add hashmap. otherwise print uppercase.

code should similar this.

map<string> lines = new hashmap(); while (keyboard.hasnextline()) {         str1 = keyboard.nextline();         stringbuilder sb = new stringbuilder(str1);         if(lines.get(str1)==null){            // not found, put hashmap , print normally.            lines.put(str1);            output.append(sb.tostring().append("\n");         }else{            // found, line repetitive, print uppercase version.             output.append(sb.touppercase().tostring()).append("\n");         }    } 

Comments

Popular posts from this blog

Command prompt result in label. Python 2.7 -

javascript - How do I use URL parameters to change link href on page? -

amazon web services - AWS Route53 Trying To Get Site To Resolve To www -