Note 1

Take Note:

Take a note while surfing.





Note With Ink

Give your Note a Colorful Tag.




Easy to Access

Stay on same information and in Sync wherever you are.

Note 2

Take Note:

Organize your information,It may take Shape.





Think With Ink

Differ your Content by Color.




Easy to Access

Easy to pull up your content from anywhere anytime.

Note 3

Take Note:

Don't Let information to miss,Because it take shape





Note With Ink

Simple an Easy Way to take a note.




Easy to Access

Get the same in next visit.

Program Discussion :: Basics
Home > Programs > Basics

1. Write a program to print next to the last word of a sentence.

Answer:

import java.io.*;
class test
{
    public static void main(String args[]) throws IOException 
    {
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        String s;
String str,str1;
int c=0;
s=br.readLine();
/* With string compariosons there may be an arrayoutofbounds exception rather that statement can be replaced with this */
        while((c<=s.length()))
        {
            /* One Method to find Second last Word */
            
            str=s.substring(0,s.lastIndexOf(" "));
            str1=str.substring(str.lastIndexOf(" "),str.length());     
c  ;
if(c==1)
System.out.print(str1);            
        }
    }
}

Post Your Answer Here:

Name *
Email

Language:

Post Your Reply Here:



Language:

Post Your Reply Here:



Language:

Post Your Reply Here:



Language:

Post Your Reply Here:



Language:

Post Your Reply Here:



Language:

Post Your Reply Here:



Language:

Post Your Reply Here:



Language:

Post Your Reply Here: