Question

KINDLY Describe the approach (in plain English) used to completing the coding below and explain the major decisions made...

KINDLY Describe the approach (in plain English) used to completing the coding below and explain the major decisions made in designing the program.

As part of your explanation, be sure to identify the Java constructs you used that are specific and relevant to the program below. Depending on the program, these may include the mechanisms for output, input, selection statements, loops, methods, and so forth.

***********BEGINNING OF CODE***************

import java.util.*;

public class CountOccurances{

public static void main(String[] args) {

Scanner userIn = new Scanner(System.in);

int arr[] = new int[7];

System.out.print("Please enter 7 integers: ");

for(int i=0; i<7; i++){

arr[i] = userIn.nextInt();

}

System.out.println("Count Occurrences in Seven Integers Using Java Single Dimension Arrays Instructions");

for(int i=0; i<7; i++){

int c = 0;

for(int j=0; j<7; j++){

if(arr[i]==arr[j])

c++;

}

System.out.println(arr[i]+":"+c);

}

}

}

***********END OF CODE***************

0 0
Add a comment Improve this question Transcribed image text
Answer #1

The code is basically ask user to enter 7 digit and store them in an array and then count the occurance of each digit in the array and print the occurance if each digit in array .

import java.util.*;

public class Main{

public static void main(String[] args) {
//Scanner is use to take input from user
Scanner userIn = new Scanner(System.in);
//initialized an array of 7 integers
int arr[] = new int[7];
//ask user to enter 7 numbers
System.out.print("Please enter 7 integers: ");

for(int i=0; i<7; i++){
//store the value in array
arr[i] = userIn.nextInt();

}

System.out.println("Count Occurrences in Seven Integers Using Java Single Dimension Arrays Instructions");
//check for occurance of each number in array
//outer loops to points to an element at i th position
for(int i=0; i<7; i++){

int c = 0;
//inner loops for comparing with other values
for(int j=0; j<7; j++){

if(arr[i]==arr[j])

c++;

}
//print the result
System.out.println(arr[i]+":"+c);

}

}
}

Add a comment
Know the answer?
Add Answer to:
KINDLY Describe the approach (in plain English) used to completing the coding below and explain the major decisions made...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • kindly Explain, briefly IN PLAIN ENGLISH, how this exercise was completed and the algorithm you used...

    kindly Explain, briefly IN PLAIN ENGLISH, how this exercise was completed and the algorithm you used /* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ // package u10a1_ooconsoleregisterforcourse; import java.util.Scanner; /** * * @author omora */ public class U10A1_OOConsoleRegisterForCourse { /** * @param args the command line arguments */ public static void main(String[] args) { // TODO...

  • The following code is a Java code for insertion sort. I would like this code to...

    The following code is a Java code for insertion sort. I would like this code to be modified by not allowing more than 10 numbers of integer elements (if the user enters 11 or a higher number, an error should appear) and also finding the range of the elements after sorting. /* * Java Program to Implement Insertion Sort */ import java.util.Scanner; /* Class InsertionSort */ public class InsertionSortTwo { /* Insertion Sort function */ public static void sort( int...

  • Please explain if the following code is actually correct. If the following code correct, please explain...

    Please explain if the following code is actually correct. If the following code correct, please explain why the code works and is also correct. Don’t use * Java’s Integer .toBinaryString(int) in this program./* According to the textbook and the instructor, I am not supposed to use arrays such as int binary[] = new int[25]; I guess this is the reason why this problem is starting to look kind of hard.   Chapter 5 Exercise 37: Java Programming * * (Decimal to...

  • the code needs to be modifed. require a output for the code Java Program to Implement...

    the code needs to be modifed. require a output for the code Java Program to Implement Insertion Sort import java.util.Scanner; /Class InsertionSort * public class Insertion Sort { /Insertion Sort function */ public static void sort( int arr) int N- arr.length; int i, j, temp; for (i-1; i< N; i++) j-i temp arrli; while (j> 0 && temp < arrli-1) arrli]-arrli-1]; j-j-1; } arrlj] temp; /Main method * public static void main(String [] args) { Scanner scan new Scanner( System.in...

  • I need a java flowchart for the following code: import java.util.*; public class Main {   ...

    I need a java flowchart for the following code: import java.util.*; public class Main {    public static void main(String[] args) {    Scanner sc=new Scanner(System.in);           System.out.print("Enter the input size: ");        int n=sc.nextInt();        int arr[]=new int[n];        System.out.print("Enter the sequence: ");        for(int i=0;i<n;i++)        arr[i]=sc.nextInt();        if(isConsecutiveFour(arr))        {        System.out.print("yes the array contain consecutive number:");        for(int i=0;i<n;i++)        System.out.print(arr[i]+" ");       ...

  • Java Im doing a binary search on an array and need to allow as many queries...

    Java Im doing a binary search on an array and need to allow as many queries as possible and cannot figure out how to. The output should read something like this. Enter a number. 3 3 is a prime number. Enter another number. 4 4 is not a prime number. Enter another number. 8 Current file not large enough for 8. Enter another number. -1 Bye. My code so far looks like this. public static void main(String[] args)    {...

  • draw a flew chart for this code // written by Alfuzan Mohammed package matreix; import java.util.Scanner;...

    draw a flew chart for this code // written by Alfuzan Mohammed package matreix; import java.util.Scanner; public class Matrix {    public static void main(String[] args) {        Scanner scanner = new Scanner(System.in);    System.out.print("Enter number of rows: first matrix ");    int rows = scanner.nextInt();    System.out.print("Enter number of columns first matrix: ");    int columns = scanner.nextInt();    System.out.print("Enter number of rows: seconed matrix ");    int rowss = scanner.nextInt();    System.out.print("Enter number of columns seconed matrix:...

  • need help editing or rewriting java code, I have this program running that creates random numbers...

    need help editing or rewriting java code, I have this program running that creates random numbers and finds min, max, median ect. from a group of numbers,array. I need to use a data class and a constructor to run the code instead of how I have it written right now. this is an example of what i'm being asked for. This is my code: import java.util.Random; import java.util.Scanner; public class RandomArray { // method to find the minimum number in...

  • Can you help me with this code in Java??? import java.util.Scanner; public class Main { public...

    Can you help me with this code in Java??? import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scan = new Scanner(System.in); int rows = 3; int columns = 4; int[][] arr = new int[rows][columns]; for(int i = 0; i < rows; ++i) { for(int j = 0; j < columns; ++j) { System.out.println("Enter a value: "); arr[i][j] = scan.nextInt(); } } System.out.println("The entered matrix:"); for(int i = 0; i < rows; ++i) { for(int j...

  • In JAVA Thank You What is the exact output produced by running the method test? /**...

    In JAVA Thank You What is the exact output produced by running the method test? /** * TestSwap.java * Demonstrates parameter passing involving arrays and integers, * scope of variables, flow of control, and overloaded methods. */ public class TestSwap { public void swap (int x, int y) { int temp; temp = x; x = y; y = temp; System.out.println("Inside swap version 1:"); System.out.println("x = " + x); System.out.println("y = " + y); } public void swap (int[] a,...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT