Submitted by: Submitted by JaeEunAii
Views: 139
Words: 2047
Pages: 9
Category: Other Topics
Date Submitted: 08/20/2013 03:47 AM
Exercise1
import java.io.*;
public class LastWord
{
public static void main(String[] args) throws IOException
{
BufferedReader sent = new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter your sentence: ");
String sentence= sent.readLine();
String last = sentence.substring(sentence.lastIndexOf(" "));
System.out.println("The last word of your sentence is: " + last);
}
}
Exercise1
import java.io.*;
public class LastWord
{
public static void main(String[] args) throws IOException
{
BufferedReader sent = new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter your sentence: ");
String sentence= sent.readLine();
String last = sentence.substring(sentence.lastIndexOf(" "));
System.out.println("The last word of your sentence is: " + last);
}
}
Exercise2
import java.io.*;
public class NumberOfPs
{
public static void main(String arg[]) throws IOException
{
BufferedReader word = new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter your sentence: ");
String input = word.readLine();
String[] bilang =input.split("");
int count = 0;
for(int j = 0; j <bilang.length ;j++)
{
if(bilang[j].equalsIgnoreCase("p"))
{
count++;
}
}
if(count==1)
System.out.println("Your sentence has " + count +" P in it");
else
System.out.println("Your sentence have " + count +" P's in it" );
}
}
Exercise2
import java.io.*;
public class NumberOfPs
{
public static void main(String arg[]) throws IOException
{
BufferedReader word = new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter your sentence: ");
String input = word.readLine();
String[] bilang =input.split("");
int count = 0;
for(int j = 0; j <bilang.length ;j++)
{...