So i created a method that basically similar to Math.pow, but using recursion.However, it works fine except it prints the final result twice, how do i get rid of the last repeated number ? here is my method :-
public static int recursion(int base, int degree) {
if (degree > 0) {
base = base * recursion(base, degree - 1);
System.out.println(base);
I wrote a code for a "skydiving" program that randomly selects the "maneuvers" to be performed by the skydiver during his skydive. I am almost done with the program. I just need to figure out how to print non repeated maneuvers for each round. Each round may not consist of two of the same maneuvers. The program that I wrote randomly picks the maneuvers but sometimes it still prints out two of the same maneuvers for each round.The following is my code.
import java.util.Scanner; import java.util.Random; ///v.0 public class Testpart2 {
I wrote a code for a "skydiving" program that randomly selects the "maneuvers" to be performed by the skydiver during his skydive. I am almost done with the program. I just need to figure out how to print non repeated maneuvers for each round. Each round may not consist of two of the same maneuvers. The program that I wrote randomly picks the maneuvers but sometimes it still prints out two of the same maneuvers for each round.
The following is my code
import java.util.Scanner; import java.util.Random; ///v.0 public class Testpart2 { public static void main(String[] args) { Random randomNumbers=new Random();
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}
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);
public class ProcessMarks { private static final int NMARKS = 125;
[Code] ...
Result (it's repeat number): *Mode is = 53 *Mode is = 53 *Mode is = 53 *Mode is = 53 *Mode is = 53 *Mode is = 62 *Mode is = 62 *Mode is = 62 *Mode is = 62 *Mode is = 62 *Mode is = 67 *Mode is = 67 *Mode is = 67 *Mode is = 67 *Mode is = 67 *Mode is = 77 *Mode is = 77 *Mode is = 77 *Mode is = 77 *Mode is = 77 *Mode is = 78 *Mode is = 78 *Mode is = 78 *Mode is = 78 *Mode is = 78 *Mode is = 85 *Mode is = 85 *Mode is = 85 *Mode is = 85 *Mode is = 85
Result that i want it to be (number appear only once):
*Mode = 53, 62, 67, 77, 78, 85
or
*Mode is = 53 *Mode is = 62 *Mode is = 67 *Mode is = 77 *Mode is = 78 *Mode is = 85
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....
Operating System = Windows 7 version 6.1 running on amd64 Java; VM; Vendor = 1.8.0 Runtime = Java HotSpot(TM) 64-Bit Server VM 25.0-b70
Detect a bug in Java, specifically in the Calendar class will getDisplayName method. I put in the message code showing the error. If the code is executed you can see that the month March be repeated 2 times jumping the month of February.
Code Example:
import java.util.Calendar; import java.util.Locale; public class BugInCalendarDisplayName { public static void main(String[] args) { Calendar aMonth = Calendar.getInstance(); aMonth.set(Calendar.MONTH, 0);
[Code] ....
Obtained results of the code execution:
ENERO MARZO MARZO ABRIL MAYO JUNIO JULIO AGOSTO SEPTIEMBRE OCTUBRE NOVIEMBRE DICIEMBRE
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 a beginning Java Program I have been working on that creates a number guessing program where the computer guesses a number that the user is thinking of within a certain range. I so far have the program below, but need getting rid of a few kinks/ adding features.
-First, I need to set it up so that the user will be prompted and give a range. It should run and produce something like this:
Welcome to this first-ever mind-guessing program!
Please pick a range (higher than 1 and no larger than 50): 32
You will choose a number between 1 and 32... and I will try to guess it.
With each of my guess, you will tell me whether I am too high (h or H), too low (l or L), match (m or M), or you want to quit (q or Q). My objective is to find the number using as few guesses as possible.
-Second, the game is supposed to give up and restart after failing the five, guesses, but for some reason, after it fails the fifth time, it prompts a fifth guess once again instead, then restarts after- I need to prevent this, so that it should look something like this:
My fourth guess is 17: h My guess is too high?
My fifth guess is 16: h *** I am unlucky this round. I give up.
Let's play!
My first guess is 10: etc..
import java.util.*; import java.lang.Math; public class numguessprac1 { // Declaring variables public static String input; public static int quit; public static int guess; public static int wins;
So I am currently writing my first assignment and have run into problems with my coding. The task was to have someone enter a 5 digit number and in return, I list each number on their respective lines. We also must create an error if a number other than 5 digits was entered. My problem is that when they enter a 1 or 2,3,4,6,7,8 digit number.. the error message occurs along with the rest of the messages (listing the numbers, etc). I want the program to end (or even re-ask to enter the numbers) if they incorrectly enter the data.
trying to write a program that takes a user inputted number and converts it to a binary number.
Here's what I have:
package com.java2novice.algos; import java.util.Scanner; public class Converter { static Scanner console = new Scanner(System.in); public void printBinaryFormat(int number){ int binary = console.nextInt();
In a forest, there are some bamboo trees .The length of each tree get doubled during winter and increases by one unit in summer , write a Java program to calculate the total length of n number of bamboo trees in M number of seasons. The season always starts with winter.
import java.util.Scanner; public class Tree { public static void main(String args[]) { int length; int season;
We have triangle made of blocks. The topmost row has 1 block, the next row down has 2 blocks, the next row has 3 blocks, and so on. Compute recursively (no loops or multiplication) the total number of blocks in such a triangle with the given number of rows.
I am trying to create a method that prints the square root of a number up to a certain number. It needs to take a single int parameter for example "n" , and then print all of the (positive) even perfect squares less than n, each on a separate line. I want the method to be called something like this:
public void Squares(int n) { }
I need the output to look something like this:
Example: if n = 40, your code should print
4 16 36
So I have been working for a few hours now and am really stuck.
This is what I have so far:
int count = 0; int n = 4; int max = n; while(count < max) { System.out.println(n); n = n * n; count++;
I am working on a little nothing project, but I wanted to create a random number generator for a silly game where the user guesses the number.I have used google, but they are using LOG statements, what it does.
//read the file //make the numbers 1 string line //count the number of repetitiveness in the string for the numbers //display four lowest ones
import java.io.*; import java.util.*; public class Lottery2
[Code] ....
when I run it the array gets sorted but how do i keep the data in other words
what it is supposed to do is grab numbers from a file, and give me the lowest 4 numbers back. I know the numbers using the array but how do i pull out the lowest 4 and keep the data true no matter what numbers or how many of them are in the file.
I am 4 weeks into my Intro to Java course and I am having a bit of trouble with my code. I need to make a program that will take a user inputted number, space the numbers out, then add them to a total sum. What I am having a hard time with is when I enter a negative number. I can't figure out what I need to do to have my program ignore the "-" in the string.
import java.util.*; public class Week4_Programming_Problem { static Scanner console = new Scanner(System.in); public static void main(String[] args) { int number, digit, sum=0; char digitPos;
i am trying to store a number of different value cards for a number of players. E.g there can be 2 , 4 or more players and each player can have any number of cards.
I have decided to use an arraylist for cards and tried using an array for players. But after coding and reading some information online, i realised that it is not possible to have an array of arraylist.
1. Write a Java program that randomly generates a five-digit lottery number and prompts the user to enter a five-digit number. Each digit in the number is in the range between 0~9. The program should determine which prize the user wins according to the following rule:
- The user wins the first prize if the user input matches all five digits in the lottery number in exact order. -The user wins the second prize if the user input matches any four digits in the lottery number in exact positions. -The user wins the third prize if the user input matches any three digits in the lottery number in its exact position. -The user wins the fourth prize if the user input matches any two digits in the lottery number in its exact position.
- The user wins the fifth prize if the user input matches any one digit in the lottery number in its exact position.here is my code. I have tried replacing the && statements with || and it always returns either case 1 or case default.
import java.util.Scanner; import java.util.Random; class Hw5 { static int getPrize(int g1, int g2, int g3, int g4, int g5, int u1, int u2, int u3, int u4, int u5) {
I'm having a hard time with this problem, this is what I have, but I can not use two integers, I have to use one integer and a string...
This is the question:
Write a method called printStrings that accepts a String and a number of repetitions as parameters and prints that String the given number of times. For example, the call:
printStrings("abc", 5);
will print the following output: abcabcabcabcabc
This is what I attempted:
public class printStringsproject { public static void printStrings(int abc, int number) { for (int i = 1; i <= number; i++) { System.out.print("abc"); } } public static void main(String[] args) { printStrings(1, 5); } }
Write a program that will display all the odd number between 1 and 15. here is the code that i use :
Scanner scan = new Scanner (System.in); int i, num=0, count_odd = 0; for(i=1; i<=15; i++) { System.out.println("please enter number "); num = scan.nextInt();