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



Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


rajnish
java multi
3 Answer(s)      5 years and 7 months ago
Posted in : Java Beginners



Advertisement
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  How does multithreading take place on a computer with a single CPU
Advertisements
Java multi-threading
Java multi-threading  What method is invoked to cause an object to begin executing as a separate thread
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 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 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 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-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
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
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>
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
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
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 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
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
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 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 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 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
what is multi-threading .?
what is multi-threading .?   what is multi-threading.what is the use in real time, with example programs
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
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
sendimg multi sms
sendimg multi sms  i want to send multiple sms from a distribution list decleared in the server...how do i connect my code to server
Multi PortType in NuSOAP - WebSevices
Multi PortType in NuSOAP  I would like to create a SOAP Server with atleast 2 PortType UserPortType and AccountPortType my problem is I cant combine both 2 PortType in the same Server page
Setting Multi-Line label on the Button
Setting Multi-Line label on the Button       This section shows you how to set the multi line label on the button in Java Swing Applications. This program uses html class
Multi-threaded Programming
Multi-threaded Programming  Write a class resourceThread which has a method run which calls display method of resource class. Resource class has synchronized display method which prints the array string. Take a string
Advertisements
 

 

 

DMCA.com