Sorting and Searching

 
 

Share on Google+Share on Google+

David Ferguson
Sorting and Searching
1 Answer(s)      6 years 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);
Ads
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);
    }
}

Ads









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
Sorting in Java
Sorting in Java  Sorting in Java
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
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
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 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
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
sorting and storing data
sorting and storing data   sorting and storing data in UITableView
searching the string in a paragraph?
searching the string in a paragraph?  how to search a string in a paragraph and display the corresponding line number and position of a string in java
Java sorting
sorting mechanism. say about Collections.Sort() & Arrays.Sort() that uses
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 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
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
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 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

Ads

 
Advertisement null

Ads