Home Answers Viewqa Java-Beginners count occourance no of time no between 0 to 9 given by user in java

 
 


viral patva
count occourance no of time no between 0 to 9 given by user in java
2 Answer(s)      7 months ago
Posted in : Java Beginners

import java.io.*; class count_no { public static void main(String args[]) { try { int [] size=new int[9]; int i,temp=0; DataInputStream dis=new DataInputStream(System.in);

           for(i=0;i<9;i++)
            {
                    int no=Integer.parseInt(dis.readLine());

                    if(no==1)
                     {
                                   temp++;
                     }

                  else if(no==2)
                   {
                        temp++;
                   }
             }System.out.println(temp);     

        }catch(Exception e){}               
     }

}

View Answers

October 12, 2012 at 8:25 PM


thanks


October 8, 2012 at 4:23 PM


Here is a java example that accepts 9 integers from the user and count the occurrence of each integer.

import java.util.*;

public class CountNumberFrequency {
               public static void main(String[] args) {
                Scanner input = new Scanner(System.in);
                int[] arr = new int[9];
                System.out.println("Enter numbers:");
                for (int i = 0; i < arr.length; i++) {
                     arr[i] = input.nextInt();
                }
                Map<Integer, Integer> map = new HashMap<Integer, Integer>();
        for (int i = 0; i < arr.length; i++) {
            int key = arr[i];
            if (map.containsKey(key)) {
                int occurrence = map.get(key);
                occurrence++;
                map.put(key, occurrence);
            } else {
                map.put(key, 1);
            }
        }

        Iterator iterator = map.keySet().iterator();
        while (iterator.hasNext()) {
            int key = (Integer) iterator.next();
            int occurrence = map.get(key);

            System.out.println(key + " : " + occurrence + " times.");
        }
    }
}









Related Pages:
count occourance no of time no between 0 to 9 given by user in java
count occourance no of time no between 0 to 9 given by user in java  ... example that accepts 9 integers from the user and count the occurrence of each...(System.in); for(i=0;i<9;i
Java Programming: Chapter 9 Exercises
programming exercises based on material from Chapter 9 of this on-line Java textbook..., and print the count at the end of the sequence. Exit the program when the user... by evaluating the user's expression at the given value of x. You will have to convert
ArrayIndexOutOfBoundsException: 0
) Java Result: 1 BUILD SUCCESSFUL (total time: 0 seconds) here is my code...ArrayIndexOutOfBoundsException: 0  I'am a newbie to java, i have...; ether.dst_mac=new byte[]{(byte)0,(byte)6,(byte)7,(byte)8,(byte)9
time
time  how to find the current system time between the user login and logout using java
Chapter 9. EJB-QL
Chapter 9. EJB-QLPrev Part I. Exam Objectives Next    Chapter 9. EJB-QLIdentify... schema. Each bean by default is given the schema name of the bean
Java file line count
Java file line count In the section, you will learn how to count the number of lines from the given file. Description of code: Java has provide various... main(String[] args) throws Exception { int count = 0; File f = new File("C
Time validation
. If the user enters the time in wrong format, it displays the error message. <... || hour > 23) { alert("Hour must be between 1 and 12. (or 0 and 23 for military time)"); document.frm.timetext.value=""; return false; } if (minute<0
Java count frequency of words in the string
Java count frequency of words in the string. In this tutorial, you will learn how to count the occurrence of each word in the given string. String...;; } str = str.toLowerCase(); int count = -1; for (int i = 0; i < str.length
Java Programming: Chapter 9 Quiz Answers
Sample Quiz Answers For Chapter 9 THIS PAGE CONTAINS SAMPLE ANSWERS to the Quiz on Chapter 9 of this on-line Java textbook. Note that in many cases, there are lots of correct answers to a given question. Question
Finding the longest word in a user given string
Finding the longest word in a user given string  In java, accept a string from the user and find the longest word in it.   The given code...; } else{ return st2; } } LongestWord(){ String word = ""; for(int i=0;i<
if i run this prog, i got exeption in thread "main" java.lang.ArrayIndexOutOfBoundsException:0 at Maxof2.main(Maxof2.java:9), whats the resolution for ths?
" java.lang.ArrayIndexOutOfBoundsException:0 at Maxof2.main(Maxof2.java:9), whats the resolution for ths... int i = Integer.parseInt(args[0]); int j = Integer.parseInt(args[1]); if(i..., ArrayIndexOutOfBoundsException:0 means that you haven't specify the arguments along
Java Programming: Chapter 9 Quiz
Quiz Questions For Chapter 9 THIS PAGE CONTAINS A SAMPLE quiz on material from Chapter 9 of this on-line Java textbook. You should be able.... Question 6: Java has a predefined class called Throwable. What does
Count words in a string method?
=br.readLine(); int count=0; String arr[]=st.split... for user input. split()method is used for splitting the given string according...Count words in a string method?  How do you Count words in a string
Count number of "*"
:"); String text = bf.readLine(); int count = 0; for (int i = 0; i...Count number of "*"  I have this code to count the number of * from...); if (c=='*' ) { count
Java Count Vowels
Java Count Vowels       In this program you will learn how to count vowels in a String. Here you... a variable- count = 0. Now, we have applied a loop here which will go up
Java count files in a directory
Java count files in a directory In this section, you will learn how to count... main(String[] args) { File f = new File("C:/Text"); int count = 0... in the given example, we have created an instance of File class and specify a directory
return 0 vs exit 0
return 0 vs exit 0  what is the difference between return 0 and exit 0 in c? i could not find any difference in their behaviour (both terminates the process execution) in a program
JAVA leftshift operator add 1 instead of 0
JAVA leftshift operator add 1 instead of 0  Hi Guys, I have a task... on that, it adds "0" on left side of value. For example, view plaincopy... this, 5 as binary : 0101 1st time left shift: 01010 2nd time left shift: 010100
PHP Array Count
between these two functions.  General Format int count( mixed... mode: 0 (by default) or 1 for COUNT_RECURSIVE  ... Array Count Function Example 1: <?php $a[0]=0; $a[8]=1; $a[2
Java get number of days between dates
Java get number of days between dates  ... the number of days between two dates, the given example has set two dates by using... and 9 for the month October. The given dates are 2008,Sep,1 and 2008,Oct,31
count in java - Java Beginners
, count of frmale is 20. what's code in java to select count from database where...count in java  Hello javamania.... i want to ask something like... is 20. i have JFrame Form(jTextField,jLabel,jButton), i want to get count
coding for given question
coding for given question  Board of Control for Cricket in India.... BCCI has assigned you task to write a program that calculates the count of best bowlers among the given lot. Input/Output Specs Input Specs Your program
Count the character in java
Count the character in java  Write a java program to count the character ââ?¬Ë?aââ?¬â?¢ typed by the user in a paragraph by implementing thread.   Count characters by implementing thread import java.util.*; class
Java Word Count - Word Count Example in Java
Java Word Count - Word Count Example in Java  ... to count the number of lines, number of words and number of characters... some strings and program will count the number of characters and number of words
what is the difference between productList==null and productList.size()==0
what is the difference between productList==null and productList.size()==0  what is the difference between productList==null and productList.size()==0? here productList is of type LIST
user input in java - Java Beginners
static void main(String[] args) { double number; int count = 0... = scan.nextDouble(); while (number != 0) { total = total + number; count...user input in java   i am trying to write a code to compute
Example: Count Bad Words
Java NotesExample: Count Bad Words Your grandmother has learned to program in Java, and one of the first things she wants to do is search thru... 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
Java count characters from file
Java count characters from file In this section, you will learn how to count...++) { char ch = third[counter]; int count = 0; for (int i = 0; i <... into string. Then we have removed all the spaces between the string using replaceAll
Java Time Zone Example
Java Time Zone Example       Converting time between time zones In this section we have written a java program which will take two Time Zone IDs as its argument and then convert
Character count by while loop
]; int count=0; for ( int i=0; i<third.length; i++){ if (ch==third[i]) count++; } boolean flag=false; for(int j=counter-1;j>=0;j--){ if(ch==third[j...Character count by while loop  Write the program to count the number
JDBC Get Row Count
JDBC Get Row Count       The JDBC Get Row Count enables you to return the row count of a query. JDBC Get Row... in JDBC Get Row Count. The code help you to understand how to count the number
Count Characters from the input string Java
Count Characters from the input string of Java In this section, you will learn how to count the occurrence of each character in the string. For this, we have...; char ch= third[counter];   int count=0;  
J2ME count character into string
J2ME count character into string  i am new in J2ME, my problem is how to count character into number, i had been research google for almost 2 days... form which allow user to input character user input helloworld then press
Record user login and logout timing In JSP
;SimpleDateFormat sdfDestination=null;   int count=0;  ... Record user login and logout timing In JSP... application of maintain record of the user Login and Logout Time  in JSP
PHP Array Count Values
array_count_values() function to count the number of variables.  General description of array_count_values() is given below: General Format...PHP Array Count Values  Sometimes  we need to count the number
Count Row - JSP-Servlet
db = "register"; String driver = "com.mysql.jdbc.Driver"; int count= 0...Count Row  Hello all, Please I need your help on how to desplay... using java servlet and html form. Thanks for your good job!   Hi friend
To Count The Elements in a XML File
in the xml file. If the given element doesn't exist it displays the '0' element... To Count The Elements in a XML File       In this section, you will learn to count the element
letter count problem - Java Beginners
letter count problem  i have a problem in my java coding to count two characters of a string. eg to count the letter "ou" in the string "How do... s.equals("") ? 0 : s.charAt(0) == cc ? 1 + countCharset(s.substring(1
To Count XML Element
To Count XML Element       In this section, you will learn to count the elements present... helps to count the XML element. It takes a xml file (as a string ) at the console
User Interface Toolkits
User Interface Toolkits User Interface Toolkits / Libraries are given below... applications and Java programming language, between Java programming language... For creating application specifically for handicapped persons Java Accessibility
Difference between error and exception ????????
Difference between error and exception ?  Can we handle a error in java if yes than give an code of an example? Difference between error... yourself or that might be thrown because of an obvious run-time error such as trying
Hibernate criteria count.
Hibernate criteria count.  How do we count rows using criteria... create Persistent class ?Hibernate uses the Plain Old Java Object (POJO) classes...(0)); } } Description: Hibernate criteria is used here as alternative to HQL
Programming: Count Words - Dialog
Java NotesProgramming: Count Words - Dialog Description Write a program which counts the number of words in text the user enters. Assume that a word... words, and so is "test this". Only count blanks if the last
How can i add a new count to this source code ? - Java Beginners
How can i add a new count to this source code ?  Hi everyone I have 5 variables 1. XTSM is between 0~200 2. XTS is between 0~2 3. XRX is 0~3 4. XHAN is 0~7 5. ZHTYPE is one of these : (1)TCHF_HLF (2)TCHSD (3)TCHFULL
How can i add a new count to this source code ? - Java Beginners
How can i add a new count to this source code ?  Hi everyone I have 5 variables 1. XTSM is between 0~200 2. XTS is between 0~2 3. XRX is 0~3 4. XHAN is 0~7 5. ZHTYPE is one of these : (1)TCHF_HLF (2)TCHSD (3)TCHFULL
Day for the given Date in Java
Day for the given Date in Java  How can i get the day for the user input data ?   Hello Friend, You can use the following code: import java.util.*; import java.text.*; class CheckDay{ public static void main
program to display frequency count of each word in a file using Hashmap, Hashset and streamtokenizer.plz help me out ..
++; } System.out.println(str+" word is repeated "+count+" time in given file... StringTokenizer(str); int count=0; while(st.hasMoreTokens...()) { // it is a HashSet word String str=iterator.next(); int count=0
Java: Example - Count occurences
Java: Example - Count occurences Problem: Count the number of times one.... //-------------------------------------------- count() int count(String base, String searchFor) { int len = searchFor.length(); int result = 0; if (len > 0) { // search only
Count characters from text file in Java
Count characters from text file Using Java Here we are going to count...;ch= third[counter];   int count=0;   for ... all the spaces between the string using replaceAll() method and then convert
Programming: Count Words - Dialog
Java NotesProgramming: Count Words - Dialog Description Write a program which counts the number of words in text the user enters. Assume that a word... of blanks+1. Declare an int variable to count the number of blanks, initializing

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.