I am having a problem of how to write a program dat will input one number consisting of five digit,separate the number and print the digits separated from one another by three spaces each.. I tried to use divisional and remainder operation but it didn't work.
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) {
which method i can use so that the program checks if the input value is a digit or else outputs a message saying that `the value entered is not a number.
I do not know how to read a name which has spaces in Java and I wish to learn. The following is my code
import java.util.*; public class Asking { public static void main(String []args) { Scanner reader = new Scanner(System.in); String [] names = new String[20]; int [] marks = new int[20];
I have to write a program that asks the user to enter an integer and then the program is supposed to display the integer each time with the rightmost digit dropped off. For example if the user enters 1048576 the program would display 104857 10485 1048 104 10 1 and 0. this is what I have so far
import java.util.*; public class Lab5 { public static void main(String[] args){ Scanner input= new Scanner(System.in); System.out.print("Enter An Integar Value: "); int number = input.nextInt(); while (number != 0){ number = number / 10;} System.out.println(number); } }
I am not getting any errors, however when i run the program and supply an integer it skips displaying all the integers in-between and automatically displays 0.
i have tried permutation with big Integer in Java. it works fine upto 4 integer input say 3456 P 2345 but nothing happens in console when i type 5 digit input..here is my code
public class cvic { public static void main(String[] args) { Scanner scan = new Scanner(System.in); System.out.print("Enter n and r: "); BigInteger n = scan.nextBigInteger(); BigInteger r = scan.nextBigInteger(); System.out.println("nPr = "+fact(n).divide(fact(n.subtract(r))));
I need to know how many four letter strings I can generate that begin with the letter "v". Now I had been testing many ways to do this but anm stuck. I can generate a single line up only a certain amount. I need it to continue till it reaches the max number. So since it needs to always start with V i eliminated the need for four and only a 3 letter string.
package javaapplication4; import java.util.Random; public class JavaApplication4 { /** * @param args the command line arguments */ public static void main(String[] args) { Random r = new Random(); int c = r.nextInt(26)+ (byte)'a';
But my requirement is inputMask should take no limit no. of digits(only).but it is taking no. of 9 which i have given in mask attribute..
And if i am not giving mask attribute and i am handling with keyFilter(....regx) but it is allowed to paste alphabetic(Char) also. so mask attribute is required.
I am trying to split a string into a String[] tokens array to declare variables for an object; however, I'm having an issue getting the string to tokenize correctly. Here's an example of the input:
a : 100 : John Smith : 20 Main St. a : 101 : Mary Jones : 32 Brook Rd.
Here is the basic code I have now, to properly sort each line of text, etc. (without the split() method):
Java Code:
while (scanner.hasNextLine()) { currentLine = scanner.nextLine(); lineScan = new Scanner(currentLine); if (currentLine.startsWith("/") || currentLine.trim().isEmpty()) continue;
[Code] ....
I was able to eliminate the comments and identifiers from the text by trimming the first two characters of the string. For the split, I tried String[] tempArray = currentLine.split("s+"); however, that also took the spaces out of the addresses and names...so the results looked like this:
100 John Smith 20 Main St.
As you can see, it splits via space regardless, including where I replaced all the :'s with spaces. Is there any way to do this?
My method below works fine to print a matrix but when it prints every row, it is printing extra 4 white spaces which is not required. How can I delete those extra spaces at the end? when I use
I am trying to figure out how to import a txt file that has a color and a four digit number. Everything that I have tried comes up with some kind of error.
I couldn't find an edit button. I need to store the String and int from the txt file into an array. The problem that I keep having is that the compiler seems to want it as either two ints or two Strings.
public class Oott { public static void main ( String[] arguments) { System.out.println( 1.0 / 13.0); } }
When I run this it prints out "0.07692307692307693". Is that an error? Rounded correctly it should be "0.07692307692307692", shouldn't it? The repeating series is "076923". Do the Java specs allow a value returned that's off in the least significant digit?
I am working on a small brain teaser project where I am taking a string input from a Scanner, and turning into ascii. The problem comes into play when the string has a space in it, so if the question is what's your name? and you say Michael Jackson, Michael gets converted then Jackson becomes the answer to the next question, rather then the second portion of the current string.
This is an older version of what I'm doing currently, but it had the same basic problem with spaces.I will say I did my current version entirely different.
nner user_input = new Scanner (System.in); //Creates a string String favoriteFlick; System.out.println("Enter the title of your favorite film?"); favoriteFlick = user_input.next();
My method below works fine to print a matrix but when it prints every row, it is printing extra 4 white spaces which is not required. How can I delete those extra spaces at the end? when I use
public class ArrayPrinter { public static void main(String[] args) { int[] oneD = {5, 6, 7, 8}; PrintArray(oneD); } public static void PrintArray(int[] Arr) { System.out.println ('['); for (int i =0; i >= Arr.length; i++) { System.out.print (Arr[i]); if (i < Arr.length){ System.out.print(", "); } System.out.print (']'); } } }
I tried to format this to enhance readability but I'm not sure if I managed to improve it any... This code should be printing the contents of the array with spaces and commas its just printing [. I think this is because Arr is empty for some reason but I'm not sure why it would be when it gets the values of oneD passed to it.
I'm trying to output a ten digit phone number as a string on one file, and write another program to write it as a long because I don't know what value I need to use in order to get the code to run properly on either one.
I have to write a program that inputs a 5 digit integer from the keyboard and prints if the input number is a palindrome or not. I got it to work, but when my result prints it says "0 is a palindrome" or "0 is not a palindrome". How can I get rid of the 0 and replace it with the number input by the user?
import java.util.Scanner; public class Palindrome { public static void main(String[] args) { int number; int digit; int temp;
How do I compare an array (or maybe int?) (example: 3572) to a 4digit number from random generator? how many of the four digit match the generated numbers.