So I'm trying to write a program that prints out the "most-repeated integer" in an Array.
For example: if an array contains {1,2,2,3} It would print out 2 as the result.This is what I got so far and according to my knowledge I think I'm correct but for some reason it doesn't work.. Please give me some inputs.
public class MostInt{
public MostInt (){
int[] array = {0};
for(int i = 0;i>array.length;i++){
if(i==i++){
System.out.println(i);
Write a program that asks the user for an integer andthen prints out all its factors in increasing order. Use a class FactorGenerator with a constructor FactorGenerator(int numberToFactor) and methods nextFactor and hasMoreFactors. Supply a class FactorTester whose main methods reads a user input, constructs a FactorGenerator object and prints the factors.
Here is what I have so far for my main class and tester class
public class FactorGenerator { int factor; int number; int x; FactorGenerator(int numberToFactor) { number = numberToFactor; }
I have to make a program that prompts the user to enter 10 numbers and at the end it prints out the distinct numbers and then the other numbers that weren't repeated...
I have the part where it prints out the distinct numbers but I stuck on how to make it print out the other numbers that didn't repeat...
import javax.swing.JOptionPane; public class DistinctNumbers { public static void main(String[] args) { String getInput; int input; int[] numbers = new int[10];
I have made a program which finds the number of occurrence of the words. It is as follows :
public class B { public static void main(String[] args) { Map<String, Integer> mp = new LinkedHashMap<String, Integer>(); String s = "This is me tarun ohri This"; Scanner p = new Scanner(s); int i = 0;
[Code] .....
Output is coming {This=0, is=1, me=1, tarun=1, ohri=1}
Write a program to create an integer array of size 20. Then, the program should generate and insert random integers between 1 and 5, inclusive into the array. Next, the program should print the array as output.
A tremor is defined as a point of movement to and fro. To simulate it, the program will generate a random number between 0 and 19, which represents the location in the array (i.e. index number). Then, the 3 numbers to the left and right of this location should be reset to the value 0. If there isn't 3 numbers to the left and right you may assume a lesser number depending on the boundaries of the array.
Then, the final array should be printed as output. There is no user input for this program.Your program must include, at least, the following methods:
-insertNumbers, which will take as input one integer array and store the random numbers in it. -createTremor, which will generate the random number as the location and return it.
package question.pkg3; import java.util.Scanner; public class Question3 { public static void main(String[] args) { // TODO code application logic here Scanner Luka=new Scanner(System.in); double sum=0;double count=0; int[] a=new int[10];
[code]....
I'm required to write a program that allows the user to enter up to 10 integer grades into an array. Stop the loop by typing in ‐1. Your main method should call an Average method that returns the average of the grades.I There's something wrong with my program , the count always stays 0 and the sum is always 1 less than the actual sum.Sample input and output :
Enter grade 1: 8 Enter grade 2: 9 Enter grade 3: 10 Enter grade 4: 5 Enter grade 5: 8 Enter grade 6: 9 Enter grade 7: -1 output
Average grade is 8.1666666667On line 13 I had count=count+1 ;
I was trying to create a java program which can remove the repeated characters in a String. For ex-
Input: kamehamehaaa Output: kameh
Here is my code:-
import java.util.Scanner; class replace { public static void main (String args[]) { Scanner br = new Scanner(System.in); System.out.println("Enter a word");
[Code] ....
On executing the program, StringOutOfBoundsIndex error occurs.
So in my parallel array i read from a textfile of strings and if i enter the string into the string array and if strings are repeated i store it in a parallel array that counts repeated instances. I'm supposed to get 27 15 21 23 20 but instead i get 106 0 0 0 0....
When I run this code, it is supposed to get one value from turnTimer(); and return it, just as a test. This works when I enter a valid pit. For example. If I were to input "A" when it's player one's turn, it will return 1, like it should. However, if I were to type "H" when it's player one's turn, it returns "Not a valid pit!"(like it should) but then it also returns 12. It shouldn't know that H is 12 because it's in a separate method. I'm confused as to why it's printing both values.
import java.util.*; public class Mancala { static Scanner input = new Scanner(System.in); public static int pit; public static void main(String[]args) { Mancala mancala = new Mancala(); int[] board = {0,3,3,3,3,3,3,0,3,3,3,3,3,3};
When I run this code, it is supposed to get one value from turnTimer(); and return it, just as a test. This works when I enter a valid pit. For example. If I were to input "A" when it's player one's turn, it will return 1, like it should. However, if I were to type "H" when it's player one's turn, it returns "Not a valid pit!"(like it should) but then it also returns 12. It shouldn't know that H is 12 because it's in a separate method. I'm confused as to why it's printing both values.
import java.util.*; public class Mancala { static Scanner input = new Scanner(System.in); public static int pit; public static void main(String[]args) { Mancala mancala = new Mancala(); int[] board = {0,3,3,3,3,3,3,0,3,3,3,3,3,3};
I was told to create a program that prints the time between 00:00 (0:00 a.m.) and 23:45 (11:45 p.m.) in the 24-hour clock and 12-hour clock format like this:
The second message dialog result is always 0 ... i want to find the minimum grade...
import javax.swing.*; import java.util.Arrays; public class Parrarrapapa{ public static void main (String[]args){ String length = JOptionPane.showInputDialog("Number of students");
import java.util.Scanner; public class smallestnumber { public static void main(String args[]) { Scanner input=new Scanner(System.in); int smallest =0; int number;
[Code]...
here is the output of my code:
Enter the number 88 Enter the number 8 Enter the number 6 Enter the number 55
I am trying to write a java program that prints out the number that is the mathematical constant e. As you input a number, the larger it gets , the closer it comes to 2.71828 . Here is my code:
//taylor series that prints out e^1=1+1/1!+1/2!+1/3!+..... import java.util.Scanner; public class taylor_1 { public static void main(String args[]) { Scanner input=new Scanner(System.in); int factorial =1;
Write a program (TwoIntegers.java) that prompts the user to enter two positive integers and prints their sum (by addition), product (by multiplication), difference (by subtraction), quotient (by division), and remainder (by modulation). When the user enters 5 and 3, the output from your program should look exactly like the following:
Enter two positive integers: 5 3 The sum is 8. The product is 15. The difference is 2. The quotient is 1. The remainder is 2.
import java.util.Scanner; public class TwoIntegers { public static void main(String[] args) { System.out.println("Enter two positive integers: "); Scanner userInput = new Scanner("System.in"); int integer1 = userInput.nextInt(); int integer2 = userInput.nextInt();
I'm trying to create a circular array which prints out 8 numbers that increase by one and don't exceed 9. If they do, the remaining numbers are printed from 0 on-wards. I have code below which does this job, but it doesn't really use an array to loop back.
Java Code:
package Practice;
public class Practice { public static void main(String[] test) { number(7); number(9);
I have to make two classes. The first one crates an instance of an array of several integers and prints data (average, greatest, lowest, et cetera) based on the second class, which contains the methods. I'm having a problem with the syntax for the first class required to use the methods.
Here's a shortened version of what I have right now just based on processing the number of integers in the array (because if I can get just one method properly connected, I could figure out everything else).
Driver
import java.util.Arrays; public class ArrayMethodsDriver { //Creates the ArrayMethods object public static void main(String[] args) { int[] a = {7,8,8,3,4,9,8,7};
[Code] ....
When I try to compile this, I currently get the "class expected" error on the count part.
I am to design a program in java that will allow a user to Input a list of your family members along with their age and state where they reside. Determine and print the average age of your family and print the names of anyone who live in Texas. I have tried but my results are wrong.
I'd like to know how to return a new array, I wrote in a method below the main method. I want to print the array but system.out.print doesn't work for arrays apparently. What structure i should use?
How can I access the index of one character array and store those indexes into another array? I need this array of indices so as to perform an addition with another array.
Suppose I have a char array that stores all the letters of the alphabet (say alpha) and I have an another char array (say letter) that contains some letters in it. I want to retrieve those letters from the "letter" array and check its index in the "alpha" array and store that index into another integer array.
And I want the integer value to be displayed, instead of double. This works, but when the program rounds the double into integer, if the number is for example 75,56 (this is %) or 3,5 I would like it to be rounded in 76 (or 3,6 for the other example) since as it is at this moment, when all the calculated integers are summed, the result is not 100%, but 99%.
// 1 ***** student writes this method /** Searches for key in integer array named arr // arr is an instance variable of the class and has been instantiated and filled with random values. // @param key value to search for // @return if key is found, the index of the first element // in array whose value is key; if key is not found, // the method returns -1 */
public int sequentialSearch( int key ) { // Note: To animate the algorithm, put this method call as the first statement in your for loop // animate( i, 0 ); // where i is the index of the current array element return 0; // replace this statement with your return statement } // end of sequentialSearch