Program Discussion :: Basics
Home > Programs > Basics

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

Answer:

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class StringWordIBM 
{

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

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: