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



Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


David Ferguson
Sorting and Searching
1 Answer(s)      2 years and 11 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 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 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
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 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
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
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
Advertisements
 

 

 

DMCA.com