Click here to Skip to main content
15,399,081 members

Comments by Member 13954890 (Top 18 by date)

Member 13954890 3-Jul-19 12:56pm View
   
yes it worked :D Thanks a lot but why it's throwing garbage value when converting character array(i.e ch) to String using toString()?
Member 13954890 2-Jul-19 3:42am View
   
I want to print all the marks which I got from users by using getMarks() but I'm getting some garbage value. Where I'm wrong and how to fix it?
Member 13954890 2-Jul-19 1:24am View
   
ok thank you
Member 13954890 1-Jul-19 10:48am View
   
Thank you so much @wseng
Member 13954890 23-Jun-19 4:37am View
   
it's not taking gender after that and directly asking for Hailing from.
Member 13954890 15-Sep-18 4:47am View
   
Because I want my words without any special characters like @ and no. That's why I'm splitting my words into characters and then removing all special characters and no. from it and then again converting it to words.
Member 13954890 14-Sep-18 13:39pm View
   
public class dhshk
{
public static SortedMap<String, Integer> CountW(String s,String ss)
{
SortedMap<String,Integer> ht=new TreeMap<String,Integer>();
int count=1;
if(s.contains(ss))
{
if(!ht.containsKey(ss))
{
ht.put(ss,count);
}
else
{ count=count+1;
}
}
return ht;
}
public static void main(String args[])
{
SortedMap<String,Integer> hte=new TreeMap<String,Integer>();
String s="hello! my my name@ is pragya";

String wo[]=s.split(" ");

for(String w:wo)
{
System.out.println(w);
}
String word;
for(int i=0;i<wo.length;i++)
{
word=wo[i].toLowerCase();

List<character> li=new ArrayList<character>();
for (char ch:word.toCharArray())
if(ch>='a' && ch<='z')
li.add(ch);
String ss="";
for(char ch:li)
ss=ss+ch;
hte=CountW(s,ss);
System.out.println(hte);
}
}
}
Still i'm not getting the answer.
Member 13954890 14-Sep-18 13:37pm View
   
Sir i'm really not getting how to do it.I tried a lot but each and every time i got struck.Will you please help me out?It's working quite fine with void. I guess there is some problem with for loop when using string as my return type but however i'm not getting how to code it when using string as my return type?
.
Member 13954890 14-Sep-18 13:18pm View
   
no it's showing error-'The method ust return result of type string'. In output i want clear words i.e. after ignoring special characters and no. and converting all to small letters like :
Hello!
my
my
Name@
is
Pragya12
clear words i.e. after ignoring special characters and no. and converting all to small letters are:
hello
my
my
name
is
pragya
Member 13954890 14-Sep-18 12:57pm View
   
sir what's the difference between sortedmap and a hashtable?
Member 13954890 14-Sep-18 10:26am View
   
public class stringtowords
{ public static Hashtable<String, Integer> CountW(String s,String ss)
{
Hashtable<String,Integer> ht=new Hashtable();
int count=1;
if(s.contains(ss))
{
if(!ht.containsKey(ss))
{
ht.put(ss,count);
}
else
{ count=count+1;
}
}
return ht;
}
public static void main(String args[])
{
Hashtable<String,Integer> hte=new Hashtable();
String s="hello! my my name@ is pragya";

String wo[]=s.split(" ");

for(String w:wo)
{
System.out.println(w);
}
String word;
for(int i=0;i<wo.length;i++)
{ word=wo[i].toLowerCase();

List<character> li=new ArrayList<character>();
for (char ch:word.toCharArray())
if(ch>='a' && ch<='z')
li.add(ch);
String ss="";
for(char ch:li)
ss=ss+ch;
hte=CountW(s,ss);
System.out.println(hte);
}
}
}
but for each word it's printing 1 only
I'm not getting where i'm going wrong.
Member 13954890 14-Sep-18 10:09am View
   
Deleted
public class stringtowords
{ public static Hashtable<String, Integer> CountW(String s,String ss)
{
Hashtable<String,Integer> ht=new Hashtable();
int count=1;
if(s.contains(ss))
{
if(!ht.containsKey(ss))
{
ht.put(ss,count);
}
else
{ count=count+1;
}
}
return ht;
}
public static void main(String args[])
{
Hashtable<String,Integer> hte=new Hashtable();
String s="hello! my my name@ is pragya";

String wo[]=s.split(" ");

for(String w:wo)
{
System.out.println(w);
}
String word;
for(int i=0;i<wo.length;i++)
{ word=wo[i].toLowerCase();

List<character> li=new ArrayList<character>();
for (char ch:word.toCharArray())
if(ch>='a' && ch<='z')
li.add(ch);
String ss="";
for(char ch:li)
ss=ss+ch;
hte=CountW(s,ss);
System.out.println(hte);
}
}
}
but for each word it's printing 1 only
I'm not getting where i'm going wrong.
Member 13954890 22-Aug-18 3:30am View
   
i got the output.i intialized it as str="" instead of writing null.Thanks a lot.
Member 13954890 22-Aug-18 3:24am View
   
Deleted
error is showing if i don't initialize str.When i initialize it to null then my output is null then result.e.g. null9842
Member 13954890 22-Aug-18 3:01am View
   
Code is working fine and i'm getting the output in individual manner like 9
8
4
2
i want to display my output in a single line like 9842.For this i'm trying to convert my int array into a string and display that string.But I'm not able to do so.what should i do then?
Member 13954890 20-Aug-18 14:47pm View
   
Sorry! I'm not getting you.Will you please help me with code? Thanking you in advance.
Member 13954890 20-Aug-18 14:19pm View
   
hey! I want to sort it in descending order.Since i'm using primitive datatype i can't use sort(arr.Collections.reversedorder).Then what is the alternative?Here is my code:
import java.lang.*;
import java.util.*;

public class sort_string
{
public static void main(String[] args)
{
//String result = "";
System.out.println("enter string\n");

Scanner kbd = new Scanner(System.in);
String input = kbd.nextLine();
char[] arr=input.toCharArray();
Arrays.sort(arr);
String sorted=new String(arr);
System.out.println(sorted);
}
}
the above code is working fine but it takes 0 in the first position.I want something like that-> input:936703 output:303679 so that the length of a no. remains same.
Member 13954890 20-Aug-18 12:16pm View
   
It doesn't sort the digits in ascending order.I want to sort all the digits of a no. in ascending order.(except 0 which should always occupy the 2nd position such that the length of the no. remains same)
e.g. input: no.=692204 output: 220469
input: no.=790402 output: 200479