11
Java vs. You

Java vs. You. Problem 1 Write a program to find the total no of Even and Odd numbers between 1 to 100. *Using any Loop

Embed Size (px)

Citation preview

Page 1: Java vs. You. Problem 1 Write a program to find the total no of Even and Odd numbers between 1 to 100. *Using any Loop

Java vs. You

Page 2: Java vs. You. Problem 1 Write a program to find the total no of Even and Odd numbers between 1 to 100. *Using any Loop

Problem 1

Write a program to find the total no of Even and Odd numbers between1 to 100.*Using any Loop

Page 3: Java vs. You. Problem 1 Write a program to find the total no of Even and Odd numbers between 1 to 100. *Using any Loop

Problem 2

Write a program that reads student scores, gets the best score, andthen assigns grades based on the following scheme:Grade is A if score is best -10Grade is B if score is best -20;Grade is C if score is best -30;Grade is D if score is best -40;Grade is F otherwise.The program prompts the user to enter the total number of students, then promptsthe user to enter all of the scores, and concludes by displaying the grades.

Page 4: Java vs. You. Problem 1 Write a program to find the total no of Even and Odd numbers between 1 to 100. *Using any Loop

Problem 3

Write a program that reads ten integers and displays them in the reverse of the order in which they were read

Page 5: Java vs. You. Problem 1 Write a program to find the total no of Even and Odd numbers between 1 to 100. *Using any Loop

Problem 4

(Count occurrence of numbers) Write a program that reads the integers between 1and 100 and counts the occurrences of each. Assume the input ends with 0.

Page 6: Java vs. You. Problem 1 Write a program to find the total no of Even and Odd numbers between 1 to 100. *Using any Loop

Problem 5

Write a program that reads an unspecified number of scores anddetermines how many scores are above or equal to the average and how manyscores are below the average. Enter a negative number to signify the end of theinput. Assume that the maximum number of scores is 100.

Page 7: Java vs. You. Problem 1 Write a program to find the total no of Even and Odd numbers between 1 to 100. *Using any Loop

Problem 6

Write a program that reads in ten numbers and displaysdistinct numbers (i.e., if a number appears multiple times, it is displayed onlyonce). (Hint: Read a number and store it to an array if it is new. If the number isalready in the array, ignore it.) After the input, the array contains the distinct numbers.

Page 8: Java vs. You. Problem 1 Write a program to find the total no of Even and Odd numbers between 1 to 100. *Using any Loop

Problem 7

Write a program that generates 100 random integers between 0and 9 and displays the count for each number. (Hint: Use (int)(Math.random()* 10)to generate a random integer between 0 and 9. Use an array of ten integers,saycounts, to store the counts for the number of 0s, 1s, ..., 9s.

Page 9: Java vs. You. Problem 1 Write a program to find the total no of Even and Odd numbers between 1 to 100. *Using any Loop

Problem 8

(Average an array) Write two overloaded methods that return the average of anarray with the following headers:public static intaverage(int[] array)public static doubleaverage(double[] array)Write a test program that prompts the user to enter ten double values, invokes thismethod, and displays the average value.

Page 10: Java vs. You. Problem 1 Write a program to find the total no of Even and Odd numbers between 1 to 100. *Using any Loop

Problem 9

(Find the smallest element) Write a method that finds the smallest element in anarray of double values using the following header:public static doublemin(double[] array)Write a test program that prompts the user to enter ten numbers, invokes thismethod to return the minimum value, and displays the minimum value. Here is asample run of the progra

Page 11: Java vs. You. Problem 1 Write a program to find the total no of Even and Odd numbers between 1 to 100. *Using any Loop

Problem 10

(Find the index of the smallest element) Write a method that returns the index ofthe smallest element in an array of integers. If the number of such elements isgreater than 1, return the smallest index. Use the following header:public static intindexOfSmallestElement(double[] array)