daily pastebin goal
24%
SHARE
TWEET

Untitled

a guest Apr 27th, 2018 55 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import java.util.HashMap;
  2. import java.util.Scanner;
  3.  
  4. public class FindFirstNonRepeatingChar {
  5.     public static void main(String[] args) {
  6.         Scanner s=new Scanner(System.in);
  7.         HashMap<Character,Integer> m=new HashMap<Character, Integer>();
  8.         String str=s.next();
  9.         for(int i=0;i<str.length();i++){
  10.             if(!m.containsKey(str.charAt(i))){
  11.                 m.put(str.charAt(i),1);
  12.             }
  13.             else{
  14.                 m.put(str.charAt(i),m.get(str.charAt(i))+1);
  15.             }
  16.         }
  17.         boolean flag=false;
  18.         char ans =' ';
  19.         for(int i=0;i<str.length();i++){
  20.             if(m.get(str.charAt(i))==1){
  21.                 flag =true;
  22.                 ans=str.charAt(i);
  23.                 break;
  24.             }
  25.         }
  26.         if(flag){
  27.             System.out.println((char)ans);
  28.         }
  29.         else{
  30.             System.out.println("No non-repeating character");
  31.         }
  32.     }
  33. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top