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




Have Programming Question? Ask it here!
 
 
 


David Ferguson
Sorting and Searching
1 Answer(s)      2 years and 9 months ago
Posted in : Java Interview Questions


Hi i would really be thankful if someone could help me with this

A program is required to ask users to rate the Java programming language using a number in the range 0 - 10.

The data input is ended by entering -1.

After all the votes have been counted, the program should output a table showing how many people gave each rating and the average rating.

import java.util.*;

class RateJava {

public static void main(String[] args) {
    Scanner input = new Scanner(System.in);
    System.out.print("Rate Java(0-10): ");
    int rate = input.nextInt();
    while (rate > 10 || rate < 0) {






catch(

private static class IOException {

    public IOException() {
    }
}
ArithmeticException e


    );
    {
        System.out.println("Cannot calculate average - no data");

catch(IOException


    );


    {
        System.out.println("Error reading from file");
}

} }

    }
    System.out.print("Invalid! Rate Java within the range(0-10): ");
        rate=input.nextInt();





    System.out.println("You have rated Java: "+rate);

Advertisement
View Answers

December 9, 2011 at 4:56 PM


import java.util.*;
class RateJava 
{
    public static void main(String[] args) 
    {
        int c1=0,c2=0,c3=0,c4=0,c5=0,c6=0,c7=0,c8=0,c9=0,c10=0,c11=0;
        Scanner input=new Scanner(System.in);
        int rate=0;
        do{
        System.out.print("Rate Java(0-10): ");
        rate=input.nextInt();
            if(rate>10||rate<-1){
                System.out.print("Invalid! Rate Java within(0-10): ");
                rate=input.nextInt();
            }
            if(rate==0){
                c1++;
            }
            if(rate==1){
                c2++;
            }
            if(rate==2){
                c3++;
            }
            if(rate==3){
                c4++;
            }
            if(rate==4){
                c5++;
            }
            if(rate==5){
                c6++;
            }
            if(rate==6){
                c7++;
            }
            if(rate==7){
                c8++;
            }
            if(rate==8){
                c9++;
            }
            if(rate==9){
                c10++;
            }
            if(rate==10){
                c11++;
            }
            if(rate==11){
                c1++;
            }           
        }
            while(rate!=-1);
        System.out.println();
        System.out.println("*****RATINGS*****");
        System.out.println("Number of users rated Java 0: "+c1);
        System.out.println("Number of users rated Java 1: "+c2);
        System.out.println("Number of users rated Java 2: "+c3);
        System.out.println("Number of users rated Java 3: "+c4);
        System.out.println("Number of users rated Java 4: "+c5);
        System.out.println("Number of users rated Java 5: "+c6);
        System.out.println("Number of users rated Java 6: "+c7);
        System.out.println("Number of users rated Java 7: "+c8);
        System.out.println("Number of users rated Java 8: "+c9);
        System.out.println("Number of users rated Java 9: "+c10);
        System.out.println("Number of users rated Java 10: "+c11);
    }
}


Related Tutorials/Questions & Answers:
Sorting and Searching
Sorting and Searching  Hi i would really be thankful if someone could help me with this A program is required to ask users to rate the Java programming language using a number in the range 0 - 10. The data input is ended
Java Sorting and Searching
Java Sorting and Searching   If anyone could help me with this I would be really thankful! Write a program that stores the names of these artists in a String array. The program should prompt the user to enter the name
Advertisements
Insertion, sorting and searching in array
; } Insertion, sorting and searching in array   ... to perform searching and sorting in array. In the java code given below we have... after sorting", array); // Search for element in specified array
sorting
sorting   write a program to arrange sorting in rows,column and diagonal
Sorting
Sorting  can any help me know which sorting algorithm java uses for sorting collection and arrays
sorting
sorting  write to a program to arrange the sorting in rows, column and digonal
sorting
sorting  how to do sorting without using bubble sort,selection sort
searching books
searching books  how to write a code for searching books in a library through jsp
searching technique
searching technique  Hi, i need any searching technique in java to search the data and give the all possible data by links
Sorting in Java
Sorting in Java  Sorting in Java
searching problem
searching problem  how we can make a code in core java for searching in hard disk? i have to make an antivirus as my minor project , so i have need this type code to search the virus in hard disk
searching problem
searching problem  how we can make a code in core java for searching in hard disk? i have to make an antivirus as my minor project , so i have need this type code to search the virus in hard disk
file searching
file searching  i need a prog for searching inside a text file after evry 1 min to find does it hav any new entry
searching string
searching string   how to write a program for searching a string   Hi Friend, Try this: import java.util.*; class SearchString{ public static void main(String[] args){ Scanner input=new Scanner(System.in
searching the data
searching the data  respected sir , i am making the desktop application , so how can i search the data which are stored in the mysql databses through click the button and display in jtable through netbeans dynamically
group by sorting
group by sorting  group by sorting of data in SQL
searching inside a file for details
searching inside a file for details  i created a file with name,country,state etc...when i'm searching for the name, i have to get other details like country,state etc...please do help
linear sorting
linear sorting  what is linear sorting? can any send me an example   Hi Friend, Try this: import java.util.*; class ArraySort{ public...("After Sorting: "); for(int i=0;i<arr.length;i++){ System.out.println
Searching for Code - JSP-Servlet
JSP, Servlet Searching for Code  Hi, i am looking for a jsp servlet code examples for the search function in my application.Thanks
Sorting Program
Sorting Program  To sort 10items in alphabetical order   Arrays.sort(name of ur array)   import java.util.*; class ArrayExample{ public static void main(String[] args) { String array[]=new
sorting numbers
sorting numbers  How to sort the numbers in ascending order   import java.util.*; class SortNumbers{ public static void main(String[] args) { Scanner input=new Scanner(System.in
Java sorting
sorting mechanism. say about Collections.Sort() & Arrays.Sort() that uses
sorting and storing data
sorting and storing data   sorting and storing data in UITableView
searching from database
searching from database  how to search data from data base throug search...such as contact no./lastname /firstname should give whole information from database...   Please visit the following link: Servlet search
Sorting an ArrayList
Sorting an ArrayList  print("code sample");Hello All, I am working on a program for school and I am having trouble with sorting my list. The numbers I receive in my output are correct, but not in ascending order as required
Searching an element - JSP-Servlet
Searching an element  Dear sir, sir i have an employee... in that i am doing a searching an element by empId and displaying a all... field for searching an element by the empId.and one submit button for submitting
Searching an element - JSP-Servlet
Searching an element  Dear sir, sir i have an employee table... doing a searching an element by empId and displaying a all the employee table... for searching an element by the empId.and one submit button for submitting this form.And
Sorting the array
Sorting the array  Implement a program to process votes for 5 candidates in a talent contest. The program should use a String array to hold the names of the 5 candidates and an integer array to record the number of votes for each
Java String searching.
Java String searching.  How to search a string in given String array?   import java.util.Scanner; public class StringSearch { public... and for searching we used userCity.equalsIgnoreCase(city[i
Searching English words in a string
Searching English words in a string  My task is to find English words and separate them from a string with concatenated words..for example AhdgdjHOWAREgshshYOUshdhfh I need to find if there exists any English words.   
Searching operation in JAva
Searching operation in JAva  Sir, I have made a project for the Dispatch section of my office. I have to search for letters that are dispatched on a particular date. Now there are thousands of letters dispatched on a particular
Searching operation in JAva
Searching operation in JAva  Sir, I have made a project for the Dispatch section of my office. I have to search for letters that are dispatched on a particular date. Now there are thousands of letters dispatched on a particular
Searching operation in JAva
Searching operation in JAva  Sir, I have made a project for the Dispatch section of my office. I have to search for letters that are dispatched on a particular date. Now there are thousands of letters dispatched on a particular
Searching operation in JAva
Searching operation in JAva  Sir, I have made a project for the Dispatch section of my office. I have to search for letters that are dispatched on a particular date. Now there are thousands of letters dispatched on a particular
Bubble Sorting in Java
Bubble Sorting in Java  Hi, What is Bubble Sorting? Guide me where to learn Bubble Sorting in Java? Thanks   Hi, Check the tutorial at Bubble Sorting in Java. Thanks
searching for strings in a file
searching for strings in a file  how can i search of a person and display the other details associated with the name using java gui window?   import java.util.ArrayList; import javax.swing.*; import java.awt.event.
Finding searching phrase of a search engine
Finding searching phrase of a search engine  how to find out searching phrase of a search engine..? like, if visitors enter the keyword to google, is is any possible to get that keyword
sorting Line in c
sorting Line in c  Hi I need help with sorting line in programming c asking user to enter 1-10 characters and then sort them in lower case, alphabetical and ascending order. Any help will be appreciated! please help! void
Imp-HTML Table Sorting
Imp-HTML Table Sorting   Hi, I am working on a project and as per requirement from client i have to sort a table based on the ID Column. I want... of HTML table sorting where sorting happenes whenever user clicks on column header
Sorting along life span
Sorting along life span  how to find total age in date of birth and date of death.and also sort along life span.using object class and collection API
What are the different functions in sorting an array?
What are the different functions in sorting an array?  What are the different functions in sorting an array
Array Sorting - Development process
Array Sorting  Hello sir, Now i m doing various Array sorting(Bubble,insertion,Quick,merge etc ) I want to display Array Sort in steps by step like... is the code to display array sorting with moving graphics(color)in steps
sorting array in java
sorting array in java  How to sort array in Java or JavaScript?   JavaScript Sorting array tutorial   Java Sort array of strings import java.util.*; class ArrayExample{ public static void main(String
Searching with alphabetical order - Java Beginners
Searching with alphabetical order  Hi, I want to this please help me Steps:- 1:-I have a one form of name text box with two button. 2:-user input in name text box(alphabetical order)search all fields from
Searching with alphabetical order - Java Beginners
Searching with alphabetical order  Hi, please understood my problem and send write code its very urgent I a write once again. Steps.... 2:-User input in the name text box(searching alphabetical order) name
Sorting algorithms - Java Beginners
Sorting algorithms  I'v being given an assignment and I still couldn't find a proper answer for the following questions.Can anyone pls pls help me wi it? 1)Compare and contrast efficiencies of Shell,Quick,Heap and Radix sort
Sorting the letters in a String
Sorting the letters in a String  I have recently learned how to sort different strings using the insertion sort method but I still cannot sort the letters in one particular string. For instance, if I enter in the string "Hello my
Advertisements
 

 

 

DMCA.com