Click here to Skip to main content
15,887,928 members
Home / Discussions / Java
   

Java

 
QuestionRe: java netbeans Pin
Richard MacCutchan11-Feb-15 21:44
mveRichard MacCutchan11-Feb-15 21:44 
AnswerRe: webbase chat program Pin
Member 1144139512-Feb-15 0:54
Member 1144139512-Feb-15 0:54 
GeneralRe: webbase chat program Pin
Richard MacCutchan12-Feb-15 1:02
mveRichard MacCutchan12-Feb-15 1:02 
AnswerRe: java netbeans Pin
Member 1144139513-Feb-15 4:15
Member 1144139513-Feb-15 4:15 
GeneralRe: java netbeans Pin
Richard MacCutchan13-Feb-15 4:55
mveRichard MacCutchan13-Feb-15 4:55 
QuestionSelenium WebDriver Pin
Member 114387579-Feb-15 1:55
Member 114387579-Feb-15 1:55 
QuestionRe: Selenium WebDriver Pin
Richard MacCutchan9-Feb-15 2:48
mveRichard MacCutchan9-Feb-15 2:48 
QuestionNullPointerException in java Pin
Member 114349697-Feb-15 6:03
Member 114349697-Feb-15 6:03 
Hi,I am trying to write a java code for SMS dictionary.This is my sample input and output.
Sample input:
4//the number of inputs to be given
at
on
good
no
Sample output:
66//maximum occurrence is printed here.
The conversion takes place as follows.
at->28
on->66
good->4663
no->66
This is similar to the way in which messages are typed in a basic series mobile. My code displays the conversion but the output should be the number with maximum occurrence like 66 in the above sample.I get NullPointerException while trying to save the values to a buffer.Thanks in advance.
Java

package sms;


import java.util.Arrays;
import java.util.Scanner;
class done
{

String astring;
int m=0;
String buffer[];
String temp1[];
int temp2[];
int b = 0;
char val2[]={'a','b','c'};
char val3[]={'d','e','f'};
char val4[]={'g','h','i'};
char val5[]={'j','k','l'};
char val6[]={'m','n','o'};
char val7[]={'p','q','r','s'};
char val8[]={'t','u','v'};
char val9[]={'w','x','y','z'};
 
Scanner in=new Scanner(System.in);
@SuppressWarnings("empty-statement")
void fun()
{
System.out.println("Enter the number of strings");
int num=in.nextInt();
System.out.println("enter the strings");
for(int k=0;k<=num;k++)
{
  
   astring =in.nextLine();
   b=astring.length();
   char c;
     for(int i=0;i<b;i++)
       {
           c=astring.charAt(i);
           if((c==val2[0])||(c==val2[1])||(c==val2[2]))
             { 
                 System.out.print("2");
                 temp1[i] =("2");
             } 
else if((c==val3[0])||(c==val3[1])||(c==val3[2]))
        {
            System.out.print("3");
            temp1[i] =("3");
        }
else if((c==val4[0])||(c==val4[1])||(c==val4[2]))
        {
            System.out.print("4");
            temp1[i] =("4");
        }
else if((c==val5[0])||(c==val5[1])||(c==val5[2]))
        {
            System.out.print("5");
            temp1[i] =("5");
        }
else if((c==val6[0])||(c==val6[1])||(c==val6[2]))
        {
            System.out.print("6");
            temp1[i] =("6");
        }
else if((c==val7[0])||(c==val7[1])||(c==val7[2])||(c==val7[3]))
        {
            System.out.print("7");
            temp1[i] =("7");
        }
else if((c==val8[0])||(c==val8[1])||(c==val8[2]))
        {
            System.out.print("8");
            temp1[i] =("8");
        }
else if((c==val9[0])||(c==val9[1])||(c==val9[2])||(c==val9[3]))
        {
            System.out.print("9");
            temp1[i] ="9";
        }
}
     temp2[k]=Integer.parseInt(temp1[k]);
    
}
}
}

class SMS
       {
           public static void main(String args[])
           {
               done obj;
               obj = new done();
               obj.fun();
           }                      
}

AnswerRe: NullPointerException in java Pin
Richard MacCutchan7-Feb-15 22:11
mveRichard MacCutchan7-Feb-15 22:11 
SuggestionRE: JAVA Pin
Sri01106-Feb-15 2:10
Sri01106-Feb-15 2:10 
GeneralRe: RE: JAVA Pin
Richard MacCutchan6-Feb-15 3:00
mveRichard MacCutchan6-Feb-15 3:00 
GeneralRe: RE: JAVA Pin
Akash gods7-Feb-15 5:45
professionalAkash gods7-Feb-15 5:45 
QuestionTime Pin
Member 114289684-Feb-15 21:45
Member 114289684-Feb-15 21:45 
AnswerRe: Time Pin
Afzaal Ahmad Zeeshan5-Feb-15 0:20
professionalAfzaal Ahmad Zeeshan5-Feb-15 0:20 
GeneralRe: Time Pin
Member 114289685-Feb-15 19:02
Member 114289685-Feb-15 19:02 
AnswerRe: Time Pin
Richard MacCutchan5-Feb-15 2:43
mveRichard MacCutchan5-Feb-15 2:43 
GeneralRe: Time Pin
Member 114289685-Feb-15 19:03
Member 114289685-Feb-15 19:03 
GeneralRe: Time Pin
Richard MacCutchan5-Feb-15 21:47
mveRichard MacCutchan5-Feb-15 21:47 
QuestionMedian of an Array Pin
PinkPrint3-Feb-15 13:04
PinkPrint3-Feb-15 13:04 
AnswerRe: Median of an Array Pin
Richard MacCutchan3-Feb-15 22:54
mveRichard MacCutchan3-Feb-15 22:54 
AnswerRe: Median of an Array Pin
Akash gods8-Feb-15 9:44
professionalAkash gods8-Feb-15 9:44 
GeneralRe: Median of an Array Pin
PinkPrint18-Feb-15 16:16
PinkPrint18-Feb-15 16:16 
QuestionSimple Mathematics. Pin
hansoctantan3-Feb-15 7:19
professionalhansoctantan3-Feb-15 7:19 
AnswerRe: Simple Mathematics. Pin
PIEBALDconsult3-Feb-15 7:36
mvePIEBALDconsult3-Feb-15 7:36 
GeneralRe: Simple Mathematics. Pin
hansoctantan3-Feb-15 7:48
professionalhansoctantan3-Feb-15 7:48 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.