String Methods

String Methods

View Answers

April 29, 2009 at 10:21 AM

Hi Friend,

Use the following code:

import java.util.*;

public class AverageWords{
public static void main(String []args){
Scanner scanner = new Scanner(System.in);
System.out.print("Enter first sentence: ");
String sen1 = scanner.nextLine();

System.out.print("Enter second sentence: ");
String sen2 = scanner.nextLine();

int lengthOfSen1=sen1.length();
System.out.println("len1"+lengthOfSen1);
int lengthOfSen2=sen2.length();
System.out.println("len2"+lengthOfSen2);
int totalLength=lengthOfSen1+lengthOfSen2;
int average=totalLength/2;
System.out.println("Average number of words:" +average);
}
}
Thanks









Related Tutorials/Questions & Answers:
String Methods - Java Beginners
String Methods  Greetings RoseIndia Team; Thank you for your... main(String []args){ Scanner scanner = new Scanner(System.in); System.out.print("Enter first sentence: "); String sen1 = scanner.nextLine
String toLowerCase and toUppercase methods example
.style1 { font-size: medium; } String toUpperCase() and toLowerCase() methods example:- String class provides methods toUpperCase() and toLowerCase(). Method toUpperCase() convert alphabetical characters in the string
Advertisements
Writing code with multiple Class Methods and String Arrays
Writing code with multiple Class Methods and String Arrays  So what I am trying to do is create a code that lists music artists names using user... In these classes I need to create string arrays that contain artist names, and be able
Writing code with multiple Class Methods and String Arrays
Writing code with multiple Class Methods and String Arrays  So what I am trying to do is create a code that lists music artists names using user... In these classes I need to create string arrays that contain artist names, and be able
methods
methods  PrintStream class has two formatting methods,what
methods
methods  PrintStream class has two formatting methods,what
methods
methods  PrintStream class has two formatting methods,what
String Functions In Java
String Functions In Java In this section we will see various methods of String...; Note : Many methods in String class are overloaded. Here we have not discussed all methods of String class. To read all methods of String class please refer
string
string  a java program using string function and access modifiers to automate the insurance company which will have to manage the information about...)Details of policy 5)Bonus amount Methods: 1)setthePolicyNo 2)GetthePolicyNo 3
String substring method example
a string. String class provide methods for finding substring from string. Method... .style1 { font-size: medium; } String substring() method example... index position of the sub string and second is end index position of the sub
STRING.....
STRING.....  plzz sent me d code for counting vowels in a string... gui programme
string
string   difference detween "public static void main (String[] args) " and "public static void main (String args[])" in java but it executes both... "String args[]" can mean a "string array called args which is an array
String Class in Action Script3
.style1 { font-size: medium; } String Class in Action Script3:- String class is a data type. String class provides methods for access... types of String class objects. String class have different types of constructors
string
string  String helloString = new String(helloArray); System.out.println(helloString); i am unable to understand this. could u plz explain
string
string  a java program using string function to input any string... ArrangeStringAlphabetically { public static void main(String[] args) { Scanner input=new Scanner(System.in); System.out.print("Enter string
String
String  how to add spaces with string functions.?   Hi... { public static String addSpaceToRight(String s, int n) { return String.format("%1$-" + n + "s", s); } public static String addSpaceToLeft(String s, int n
String
characters in string?   import java.util.*; class RemoveDuplicateCharatcersFromString { public static String removeDuplicates(String s... < s.length(); i++) { String st = s.substring(i, i + 1
String
String  write down the code of remove any character from a given string without using any string function   please give me the code of remove any given character from a given string without using function
string
string  a java program to input a string and display the string...*; import java.io.*; public class FirstLetter{ public static String capitalizeFirstLetter( String str ) { final StringTokenizer st = new StringTokenizer( str
string
*; class ExtractWords { public static void main(String[] args) { Scanner input=new Scanner(System.in); System.out.print("Enter String: "); String st=input.nextLine(); String str[]=st.split
string
string   just i want to a program in a short form to the given string in buffered reader for example input string: Suresh Chandra Gupta output: S. C...; public class StringTest { public static void main(String [] args
string
string  write a program to accept the string and store the reverse stream into another array and print
string
string  java prgm to find total occurence of a given string pattern in a sentence
string
string  java prgm to find total occurence of a given string pattern in a sentence
String
String  write a program using string it should replace 'c'char to integer number as 1 in whole source
String
String  How to Convert sunnapu gopal to Sunnapu Gopal in java using String
String
String  how to print in between numbers if the question "String s = "1,2,3,4,5,6,8,-25"" out must be 1 2,3,4,5,6,7,8,9,10,upto25
Methods of HttpServlet
Methods of HttpServlet  What are methods of HttpServlet
string
and also displaying that contain word? Like I want to find "a" in the string... and a character. It then count the occurrence of that character in the string and display... String_Example { public static void main(String[] args
string
string  program for String reverse and replace in c,c++,java e.g.Input:10,20,hello output:hello;20;10   Hi Friend, Try the following java...(String[] args) { String array[]=new String[5]; Scanner input
string
string  a java program using string function that computes your initials from your full name and display them   Please visit the following links: http://www.roseindia.net/tutorial/java/core/printInitials.html
factory methods in java?
factory methods in java?  what are factory methods in java?   Hi Friend, Factory methods are static methods that return an instance...(),ClassLoader.findClass(String name) etc. Thanks
static methods
static methods  why static methods cannot read or write the instance variables
Agile methods
Agile methods   Why use Agile methods?   This methods focus on shorter iterations, in which the software is brought to a releasable level of quality fairly often, usually somewhere between weekly and monthly. Short
String slice method example
.style1 { font-size: medium; } String slice() method example:- The string slice() and substring() methods functionality is same but difference... is negative that means slice() find substring end of the string
native methods
native methods  what is native methods in java?   A native method is a method that is implemented in a language other than Java. The Java native method is a great way to gain and merge the power of C or C++ programming
Functions and Methods
a string. Pass it to a function freq(String x),the function finds and prints the frequency of each vowel. (5) Write a program in Java to input a string using upper and lower case characters. Pass the string to a function lower(String x
Overriding methods
{ public void eat(String str) { System.out.println("Eating for grass"); } } class Cat extends Animal { public void eat(String str... { public void eat(String str) { System.out.println("Eating for bread
Convert an Integer type object to a String object
Convert an Integer type object to a String object   ... the Integer type object to a String object using the Integer.toBinaryString() and Integer.toHexString() methods. Here is an example that provides the usage
Functions and Methods
{ public static void decide(int side1,int side2,int side3){ String..."; System.out.println(type); } public static void main(String[] args
Creation of methods
(String[] args) { String[] names={"sandeep","deepthi","srinivas","vinay"}; String[] nums={"inc0001","inc0002","inc0003","inc0004"}; int deposite=0,withdral=0,total=0,sub=0,req=0; int initial=500; String name="",num
Servlet Methods
Servlet Methods In this section we will read about the various methods... methods that are used to initialize a Servlet, handles the request received..., the Servlet methods are called life-cycle methods of Servlet. Following
validate() and reset() methods
validate() and reset() methods   Describe validate() and reset() methods
Various methods of httpservletresponse interface
Various methods of httpservletresponse interface  What are the various methods of httpservletresponse interface
Final Methods - Java Tutorials
_TO_REPLACE_1 final methods The final method  can be declare as follows: public final String convertCurrency() The final method can't be override
methods in the applet - Applet
methods in the applet  import java.awt.*; import java.applet.Applet; public class applet1 extends Applet { String m; public void init... provides the Applet class with default implementation for all the applet methods
methods type - Java Beginners
methods type in Java  Give me an example programs of methods types in Java
Methods in Java - Java Beginners
Methods in Java  Hello. Currently i am involved in a group project...{ String question; String ans; String op1; String op2; String op3; String op4; Test(String question,String ans,String op1,String op2,String op3,String op4
ModuleNotFoundError: No module named 'methods'
ModuleNotFoundError: No module named 'methods'  Hi, My Python... 'methods' How to remove the ModuleNotFoundError: No module named 'methods... to install padas library. You can install methods python with following command
Cookie methods in jsp
Cookie methods in jsp   Define cookie methods in jsp ?    Cookie methods : clone() getComment() getDomain() getMaxAge() getName() getPath() getSecure() getValue() getSecure() getVersion

Ads