string manipulation

string manipulation

Write a program in java and accept 10 strings form the user. store them in an array. then find the string with the maaximum length and print it.

View Answers

July 25, 2012 at 11:21 AM

Here is a code that accepts 10 strings from the string and stored into array and then find the string with the maximum length.

import java.util.*;

class StringExample{
public static String compare(String st1, String st2){
if(st1.length()>st2.length()){
return st1;
}
else{
return st2;
}
}
public static void main(String []args){
String word = "";
Scanner input=new Scanner(System.in);
String stringArray[] = new String[10];
System.out.println("Enter strings: ");
for(int i=0;i<stringArray.length;i++){
stringArray[i]=input.nextLine();
}
for(int i=0;i<stringArray.length;i++){
if(i==0){
word = stringArray[0];
}
word = compare(word, stringArray[i]);
}
System.out.println("Longest word = " + word);
}
}









Related Tutorials/Questions & Answers:
string manipulation
string manipulation  Write a program in java and accept 10 strings form the user. store them in an array. then find the string with the maaximum length and print
string manipulation
string manipulation  write a java program that asks the user to enter a string(where a consonant means insert, a punctuation means return element at the top and a vowel means remove the maximum) to be applied to an initially
Advertisements
string manipulation
string manipulation  write a java program that asks the user to enter a string(where a consonant means insert, a punctuation means return element at the top and a vowel means remove the maximum) to be applied to an initially
string manipulation in xml
string manipulation in xml  im working on build.xml using apache ant... in one of the targets i am assigning a var file with the full path of .sql files present in a folder. while executing that .sql file in xml its giving me
java programmming: string manipulation
java programmming: string manipulation  WAP to accept a string from...' occurring in it   Here is a java example that reads a string from the command prompt and find the frequency of the character e in the input string
Java String manipulation
Java String manipulation  You are given two strings S1 and S2,Delete from S2 all those characters which occur in s1 also and create a clean S2 with the relevant characters deleted..write a pgm for this..pls send as soon
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 and manipulation of textual value.   In this example we have created different
Manipulation of war fie contents
Manipulation of war fie contents  How can I manipulate a specific file inside my war file without extracting it? Please help... Thanks and regards, Swapnil
JavaScript String Function
JavaScript String Function Almost every language provides special attention towards string and string manipulation, JavaScript is no exception. It provides many built-in functions to manipulate a string.  Java String Function
ModuleNotFoundError: No module named 'data-manipulation'
ModuleNotFoundError: No module named 'data-manipulation'  Hi, My... named 'data-manipulation' How to remove the ModuleNotFoundError: No module named 'data-manipulation' error? Thanks   Hi, In your
Image Manipulation in Swing AWT
Image Manipulation in Swing AWT  Sir, I'am new to Swing Programming. I have to create an application where an image is displayed on one Label. The same image has to be split in parts and stored in database pert wise. Later
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... { 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
Trouble with array manipulation
(String args[]){ Random r = new Random(); int array [] = new int...); } public static void main (String[] args){ let max = array[0... java.util.Random; public class ArrayRandom{ public static void main(String args
array manipulation - Java Beginners
void main(String[] args) { ArrayMerge am = new ArrayMerge(); int a[] = {1
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
string
string  a java program using string function and access modifiers to automate the insurance company which will have to manage the information about policy holders Data Members: 1)Policy No 2)Name of policy holder 3)Address 4
ModuleNotFoundError: No module named 'cloudsat-object-manipulation'
ModuleNotFoundError: No module named 'cloudsat-object-manipulation'  ...: No module named 'cloudsat-object-manipulation' How to remove the ModuleNotFoundError: No module named 'cloudsat-object-manipulation' error
ModuleNotFoundError: No module named 'cloudsat-object-manipulation'
ModuleNotFoundError: No module named 'cloudsat-object-manipulation'  ...: No module named 'cloudsat-object-manipulation' How to remove the ModuleNotFoundError: No module named 'cloudsat-object-manipulation' error
ModuleNotFoundError: No module named 'cloudsat-object-manipulation'
ModuleNotFoundError: No module named 'cloudsat-object-manipulation'  ...: No module named 'cloudsat-object-manipulation' How to remove the ModuleNotFoundError: No module named 'cloudsat-object-manipulation' error
ModuleNotFoundError: No module named 'django-dynamic-manipulation'
ModuleNotFoundError: No module named 'django-dynamic-manipulation'  ...: No module named 'django-dynamic-manipulation' How to remove the ModuleNotFoundError: No module named 'django-dynamic-manipulation' error? Thanks
Working with CSS(CSS Manipulation)
Working with CSS(CSS Manipulation)       Working with CSS(CSS Manipulation) These methods are used to manipulate CSS specially by getting and setting
could not execute native bulk manipulation query
could not execute native bulk manipulation query  I am insert data... Action { private static final String SUCCESS = "success"; private static final String FAILURE = "failure"; boolean flag; @Override
Mysql Date Manipulation
Mysql Date Manipulation       Mysql Date Manipulation find out the difference between two values... an example from Mysql Date Manipulation. To grasp this example, we create a table
Data Manipulation Statements
Data Manipulation Statements       Data Manipulation Statement is used to retrieve, insert, update... the following Data Manipulation Statements : Select Statement Insert Statement
String Function Program
String Function Program  The string function program is just an application of the string manipulation functions in JAVA. The program is designed to count the number of one-letter word, two-letter word, and three-letter words
How to Convert String to Date?
How to Convert String to Date?  Hi, I am new in Java and learning the Date manipulation in Java. I have to write a program in Java which converts the String into Date object. My user enters the date into input field and now I
(ii) String and String Buffer Class
(ii) String and String Buffer Class  difference between String and String Buffer Class
(ii) String and String Buffer Class
String and String Buffer Class  differences between : String and String Buffer Class
(ii) String and String Buffer Class
String and String Buffer Class  difference between String and String... between String and StringBuffer 1) String object is immutable whereas StringBuffer objects are mutable. 2) String objects are constants
String Ques
String Ques  what is difference between String str="abc"; and String str=new String("abc");   Hello Friend, Differences: 1)String str=new string("abc") creates two objects, one in heap memory and one in string
String progrm
String progrm  wap to count character of given string in java without using any method
string program
string program  wap to find single occurrence of given string in java without using any predefined method
String conversion
String conversion  I want to convert a string of mix cases(lower and upper case) to vice versa. ex. HellO should be printed to hELLo. the string comes from user using datainputstream. Also sending individual chars of string

Ads