Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


Cemone Bynum
String Methods
1 Answer(s)      5 years and 9 months ago
Posted in : Java Beginners



Advertisement
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
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
Methods of HttpServlet
Methods of HttpServlet  What are methods of HttpServlet
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 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
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... String addSpaceToRight(String s, int n) { return String.format("%1$-" + n + "s", s); } public static String addSpaceToLeft(String s, int n) { return
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   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  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
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(" "); for(int i=0
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
String
String  How to Convert sunnapu gopal to Sunnapu Gopal in java using String
String
String  write a program using string it should replace 'c'char to integer number as 1 in whole source
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 to accept the string and store the reverse stream into another array and print
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 http
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
Advertisements
 

 

 

DMCA.com