Program Discussion :: Basics
Home > Programs > Basics

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

Answer:

<p>import java.io.BufferedReader;<br />
import java.io.IOException;<br />
import java.io.InputStreamReader;</p>

<p>public class StringWordIBM <br />
{</p>

<p>   public static void main(String[] args) throws IOException <br />
   {<br />
     BufferedReader br = new BufferedReader(new InputStreamReader(System.in));<br />
     String str;<br />
     System.out.println("Enter the String : ");<br />
     str=br.readLine();<br />
     System.out.println(str);<br />
     String s[] = str.split(" ");<br />
     System.out.println("Splitted string : ");<br />
     for(int i=0;i<s.length;i  )<br />
     {<br />
       System.out.println(s[i]);<br />
       <br />
     }<br />
     System.out.println("Second Last word of String is : " s[s.length-2]);<br />
   }<br />
   <br />
}</p>

Asked In ::  IBM   TCS  

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:



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:



Language:

Post Your Reply Here: