java multi

java multi

View Answers

June 17, 2009 at 4:31 PM

Hi Friend,

Try the following code:

1)import java.util.*;
import java.util.regex.*;
public class ShortestWord{
public static void main (String args[]){
System.out.print ("Enter a sentence: ");
Scanner input=new Scanner(System.in);
String str=input.nextLine();
String[] words = str.split(" ");
String word="aaaaaa";
for (int i=0;i<words.length;i++){
if (words[i].length() < word.length())
word = words[i];
}
System.out.println("Shortest word is: "+word);
int len = word.length();
int index = 0;
int start = str.indexOf(word);
while (start != -1){
index++;
start = str.indexOf(word, start+len);
}
System.out.println("Its position is: "+index);
}
}

Thanks

June 17, 2009 at 5:48 PM

Hi Friend,

Try the following code:

import java.util.*;

public class Digits {

public static void main(String[] args) {
int oddCount=0;
int evenCount=0;
int zeros=0;
System.out.println("Enter multi digit number.");
Scanner input = new Scanner(System.in);
int number = 0;
int[] nums=new int[9];
while (input.hasNextInt(9)) {
number = input.nextInt();
String myString = Integer.toString(number) ;
nums = new int[myString.length()];
for(int i = 0; i < nums.length; i++){
nums[i] = myString.charAt(i) - '0';
}
//To find number of odds
for(int j=0;j<nums.length;j++)
if(nums[j] % 2 == 1) {
oddCount++;
}
System.out.println("Number of odds: "+oddCount);
//To find number of evens
for(int j=0;j<nums.length;j++)
if(nums[j] % 2 == 0) {
evenCount++;
}
System.out.println("Number of evens: "+evenCount);
//To reverse number
int reverse = Integer.parseInt( new StringBuffer( ""+number ).reverse().toString() );
System.out.println("Reverse Number = " + reverse );
}
}

}

Thanks

June 18, 2009 at 1:01 PM

Hi Friend,

Use following code in your Digits.java class to count the number of zeros present in the input digit.

for(int j=0;j<nums.length;j++)
if(nums[j]<1) {
zeros++;
}
System.out.println("Number of Zeroes = " + zeros );

Thanks









Related Tutorials/Questions & Answers:
Java multi-threading
Java multi-threading  What is multi-threading
Java multi-threading
Java multi-threading  What method is invoked to cause an object to begin executing as a separate thread
Advertisements
Java multi-threading
Java multi-threading  How does multithreading take place on a computer with a single CPU
java multi thread - Development process
java multi thread  Develop multi-threaded echo server and a corresponding GUI client in Java.please immediately reply me sir.its very urgent sir
Multi-Threading - Java Beginners
Multi-Threading  Consider a producer process prime-generator produces prime numbers randomly that are displayed by a consumer process called prime... the previously displayed number. You have to write a multithreaded Java program
multi threads - Java Beginners
multi threads  Hi i writing a multi threaded program in java .I m using three threads. I want to declare variables which will be available to all the threads to access. Is there a way to declare the variables as global variables
java multi - Java Beginners
java multi  Q. 1. Write a class with a special member function to input a multi digit number ( max. 9 digit) and print the following: (15) 1. total... of zeroâ??s present. Q.2. Write a program in java to input a sentence and find out
multi threading - Java Interview Questions
multi threading   1. extending a thread and 2. implementing runable interface is used in multi threading concept in both of this which one good... information over Multithreading concepts visit http://www.roseindia.net/java/thread
multi threaded program - Java Beginners
multi threaded program  Hi i m developing a multi thread program to execute a real time algorith. I m using three threads. I want to share date between three threads .Is there a way to share data from one thread to another thread
Multi line graph - Java Beginners
Multi line graph  Hi, I want a multi line graph on a single chart using jfree in java.... Can you please let me know the code... thanks... MultiLineChart("Multi Line Chart"); demo.pack
regardoing multi threads - Java Beginners
regardoing multi threads  Hi Please tell me how to declare global variables in main thread so that all other threads can use them and value will be available to all threads. Thanks
multi user chat server - Java Beginners
multi user chat server  write a multi chat server and client with step by step explanation? please send me this source code to my mail id with step by step explanation
multi threading code - Java Interview Questions
multi threading code  Hi this is Anji.My question is how to share the variable between two threads?.Can any one post the answer please
multi-threaded Java program - Java Beginners
multi-threaded Java program  Write a multi-threaded Java program to print all numbers below 100,000 that are both prime and fibonacci number (some examples are 2, 3, 5, 13, etc.). Design a thread that generates prime numbers
Balance multi-way tree implimentation reating database - Java Beginners
Balance multi-way tree implimentation reating database  I am doning a project in which I have to create a database product in java where user can... database like Access,MySQL.As we know database is based on Balance multi-way tree
implementing an algorithm using multi threads - Java Beginners
implementing an algorithm using multi threads  Hi i need to implement an algorith in multi threads.Algorithm has data dependency so i need to pass data from one thread to another thread. I am posting my algorithm which needs
Java Multi Dimensions Array - Java Tutorials
.style1 { text-align: center; } Multidimensional Arrays in Java In java, the grouping of same type of elements for storing under the same name...(element); } } } Output : C:\Program Files\Java\jdk1.6.0_18\bin>
multi language
multi language  Hello friends please help me Hi how can i do a java program using swing that changes the language like malayalam/tamil etc with languages on a drop down menu I am using netbeans IDE
Maven dependency for org.odpi.egeria - multi-tenant version 3.7 is released. Learn to use multi-tenant version 3.7 in Maven based Java projects
use this version ( org.odpi.egeria - multi-tenant version 3.7 ) in their Java...Maven dependency for  org.odpi.egeria  - Version 3.7 of multi-tenant released The developers of   org.odpi.egeria - multi-tenant project
Maven dependency for org.odpi.egeria - multi-tenant version 3.10 is released. Learn to use multi-tenant version 3.10 in Maven based Java projects
use this version ( org.odpi.egeria - multi-tenant version 3.10 ) in their Java...Maven dependency for  org.odpi.egeria  - Version 3.10 of multi-tenant released The developers of   org.odpi.egeria - multi-tenant project
Maven dependency for org.odpi.egeria - multi-tenant version 3.13 is released. Learn to use multi-tenant version 3.13 in Maven based Java projects
use this version ( org.odpi.egeria - multi-tenant version 3.13 ) in their Java...Maven dependency for  org.odpi.egeria  - Version 3.13 of multi-tenant released The developers of   org.odpi.egeria - multi-tenant project
Maven dependency for org.odpi.egeria - multi-tenant version 3.8 is released. Learn to use multi-tenant version 3.8 in Maven based Java projects
use this version ( org.odpi.egeria - multi-tenant version 3.8 ) in their Java...Maven dependency for  org.odpi.egeria  - Version 3.8 of multi-tenant released The developers of   org.odpi.egeria - multi-tenant project
Maven dependency for com.albertoquesada - multi-range version 0.1 is released. Learn to use multi-range version 0.1 in Maven based Java projects
; com.albertoquesada - multi-range version 0.1 in Java projects. Follow the step by step tutorial... - multi-range version 0.1 java library in your project. ADS_TO_REPLACE_2 Now...Maven dependency for  com.albertoquesada  - Version 0.1 of multi
Maven dependency for org.odpi.egeria - multi-tenant version 3.6 is released. Learn to use multi-tenant version 3.6 in Maven based Java projects
use this version ( org.odpi.egeria - multi-tenant version 3.6 ) in their Java...Maven dependency for  org.odpi.egeria  - Version 3.6 of multi-tenant released The developers of   org.odpi.egeria - multi-tenant project
Maven dependency for org.odpi.egeria - multi-tenant version 3.5 is released. Learn to use multi-tenant version 3.5 in Maven based Java projects
use this version ( org.odpi.egeria - multi-tenant version 3.5 ) in their Java...Maven dependency for  org.odpi.egeria  - Version 3.5 of multi-tenant released The developers of   org.odpi.egeria - multi-tenant project
Maven dependency for org.odpi.egeria - multi-tenant version 3.14 is released. Learn to use multi-tenant version 3.14 in Maven based Java projects
use this version ( org.odpi.egeria - multi-tenant version 3.14 ) in their Java...Maven dependency for  org.odpi.egeria  - Version 3.14 of multi-tenant released The developers of   org.odpi.egeria - multi-tenant project
Maven dependency for org.odpi.egeria - multi-tenant version 3.4 is released. Learn to use multi-tenant version 3.4 in Maven based Java projects
use this version ( org.odpi.egeria - multi-tenant version 3.4 ) in their Java...Maven dependency for  org.odpi.egeria  - Version 3.4 of multi-tenant released The developers of   org.odpi.egeria - multi-tenant project
Maven dependency for org.odpi.egeria - multi-tenant version 3.3 is released. Learn to use multi-tenant version 3.3 in Maven based Java projects
use this version ( org.odpi.egeria - multi-tenant version 3.3 ) in their Java...Maven dependency for  org.odpi.egeria  - Version 3.3 of multi-tenant released The developers of   org.odpi.egeria - multi-tenant project
Maven dependency for org.odpi.egeria - multi-tenant version 3.2 is released. Learn to use multi-tenant version 3.2 in Maven based Java projects
use this version ( org.odpi.egeria - multi-tenant version 3.2 ) in their Java...Maven dependency for  org.odpi.egeria  - Version 3.2 of multi-tenant released The developers of   org.odpi.egeria - multi-tenant project
Maven dependency for org.odpi.egeria - multi-tenant version 3.1 is released. Learn to use multi-tenant version 3.1 in Maven based Java projects
use this version ( org.odpi.egeria - multi-tenant version 3.1 ) in their Java...Maven dependency for  org.odpi.egeria  - Version 3.1 of multi-tenant released The developers of   org.odpi.egeria - multi-tenant project
Maven dependency for org.odpi.egeria - multi-tenant version 3.0 is released. Learn to use multi-tenant version 3.0 in Maven based Java projects
use this version ( org.odpi.egeria - multi-tenant version 3.0 ) in their Java...Maven dependency for  org.odpi.egeria  - Version 3.0 of multi-tenant released The developers of   org.odpi.egeria - multi-tenant project
Maven dependency for org.odpi.egeria - multi-tenant version 2.11 is released. Learn to use multi-tenant version 2.11 in Maven based Java projects
use this version ( org.odpi.egeria - multi-tenant version 2.11 ) in their Java...Maven dependency for  org.odpi.egeria  - Version 2.11 of multi-tenant released The developers of   org.odpi.egeria - multi-tenant project
Maven dependency for org.odpi.egeria - multi-tenant version 2.10 is released. Learn to use multi-tenant version 2.10 in Maven based Java projects
use this version ( org.odpi.egeria - multi-tenant version 2.10 ) in their Java...Maven dependency for  org.odpi.egeria  - Version 2.10 of multi-tenant released The developers of   org.odpi.egeria - multi-tenant project
Maven dependency for org.odpi.egeria - multi-tenant version 2.9 is released. Learn to use multi-tenant version 2.9 in Maven based Java projects
use this version ( org.odpi.egeria - multi-tenant version 2.9 ) in their Java...Maven dependency for  org.odpi.egeria  - Version 2.9 of multi-tenant released The developers of   org.odpi.egeria - multi-tenant project
Maven dependency for org.odpi.egeria - multi-tenant version 2.8 is released. Learn to use multi-tenant version 2.8 in Maven based Java projects
use this version ( org.odpi.egeria - multi-tenant version 2.8 ) in their Java...Maven dependency for  org.odpi.egeria  - Version 2.8 of multi-tenant released The developers of   org.odpi.egeria - multi-tenant project
Maven dependency for org.odpi.egeria - multi-tenant version 2.7 is released. Learn to use multi-tenant version 2.7 in Maven based Java projects
use this version ( org.odpi.egeria - multi-tenant version 2.7 ) in their Java...Maven dependency for  org.odpi.egeria  - Version 2.7 of multi-tenant released The developers of   org.odpi.egeria - multi-tenant project
Maven dependency for org.odpi.egeria - multi-tenant version 2.6 is released. Learn to use multi-tenant version 2.6 in Maven based Java projects
use this version ( org.odpi.egeria - multi-tenant version 2.6 ) in their Java...Maven dependency for  org.odpi.egeria  - Version 2.6 of multi-tenant released The developers of   org.odpi.egeria - multi-tenant project
Maven dependency for org.odpi.egeria - multi-tenant version 3.11 is released. Learn to use multi-tenant version 3.11 in Maven based Java projects
use this version ( org.odpi.egeria - multi-tenant version 3.11 ) in their Java...Maven dependency for  org.odpi.egeria  - Version 3.11 of multi-tenant released The developers of   org.odpi.egeria - multi-tenant project
Maven dependency for org.odpi.egeria - multi-tenant version 3.12 is released. Learn to use multi-tenant version 3.12 in Maven based Java projects
use this version ( org.odpi.egeria - multi-tenant version 3.12 ) in their Java...Maven dependency for  org.odpi.egeria  - Version 3.12 of multi-tenant released The developers of   org.odpi.egeria - multi-tenant project
Maven dependency for org.odpi.egeria - multi-tenant version 3.9 is released. Learn to use multi-tenant version 3.9 in Maven based Java projects
use this version ( org.odpi.egeria - multi-tenant version 3.9 ) in their Java...Maven dependency for  org.odpi.egeria  - Version 3.9 of multi-tenant released The developers of   org.odpi.egeria - multi-tenant project
Hi Friend...Doubt on Uni Cast & Multi Cast - Java Beginners
Hi Friend...Doubt on Uni Cast & Multi Cast  Hi Friend.. Can u plz send some Details about the Uni CAst & Multi cast in JAVA...  Hi... one-to-many connections, an example for multicast is the java eventhandling
multi thread
multi thread   Multiple Clients Connect to a server and communicate among the themselves. When a new Client is connected to the server, all other clients get the notification and they can chat with each other. Similarly when
multi dimension
multi dimension  class TwoDAgain{ public static void main(String args[]){ int twoD[][]=new int[4][]; twoD[0]= new int[1]; twoD[1]= new int[2]; twoD[2]= new int[3]; twoD[3]= new int[4]; int i, j, k = 0; for (i=0; i<4; i
Multi window
Multi window  I am making a bank app using struts 1.2. using only the struts tags and nno jsp tags and scriplets. db connected thru dao. 1st page contains all the details. when i submit this page, a new window opens and asks
Multi Threading
Multi Threading  Hi... I need to solve the following question: Input an array of 10 integers. Separate the odd numbers, even numbers, positive numbers and negative numbers by different threads. I tried to solve it but I dont
Creation Time Comparison of Multi Dimensional Array- Java Tutorials
Creation Time Comparison of Multi Dimensional Array In this section, we will compare the creation time between the different size/dimension of array.  As you know that multidimensional array is the array of arrays. Practically
what is multi-threading .?
what is multi-threading .?   what is multi-threading.what is the use in real time, with example programs
ModuleNotFoundError: No module named 'multi'
ModuleNotFoundError: No module named 'multi'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'multi' How to remove the ModuleNotFoundError: No module named 'multi'
Multi-value data - JDBC
Multi-value data  hey! actually am supposed to create this database that allows multi-value data.its supposedly going to become a very large database.only i dont know just how to begin creating it.what i need is mysql syntax
Multi value data - JDBC
Multi value data  Hello, please help,how do i use Multi-value data with mysql database. thank you  Hi friend, Plz explain your problem in details what you want and visit to : http://www.roseindia.net/jdbc/jdbc

Ads