How To Limit Users To Enter Only 12 Digit Input And Integer Value

Feb 8, 2014

I want to limit the program to only accept a 12 digit input and an integer value but I don't know how to program it,

import java.util.Scanner;
public class testing4
{
public static void main(String []args) {
Scanner reader = new Scanner(System.in);
String input;

[Code]...

View Replies


ADVERTISEMENT

How To Limit Users To Only Enter Integer Into String Variable

Feb 7, 2014

I need to allow users only enter integer into a String variable, "input" and I am not sure what statement to use.

import java.util.Scanner;
public class assq2b {
public static void main(String []args) {
Scanner reader = new Scanner(System.in);
String input,b;

[Code] ......

View Replies View Related

5 Digit Integer - Print If Input Number Is Palindrome Or Not

Apr 21, 2015

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;

[code]....

View Replies View Related

Java Lotto - Randomly Generate Five-digit Number And Prompts User To Enter Five-digit Number

Sep 25, 2014

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) {

[code]...

View Replies View Related

Digit Sum Of Integer Is Sum Of All Digits

Oct 13, 2014

Digit sum of an integer is the sum of all its digits. For example, the digit sum of 123 is 1+2+3 = 6

and the digit sum of 99 is 9 + 9 = 18.

But how to write the programm that will count those numbers?

View Replies View Related

User Enter 5 Digit Number And In Return List Each Number On Their Respective Lines

Sep 16, 2014

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.

View Replies View Related

Limit On String Input From Console

Mar 2, 2015

I am trying to make a program in which first I am entering number of charachters and then in nextline their is exactly that number of characters should be enter after than program should stop taking input from console..this is I have try so far

private static ArrayList<String> chars;
static String inputdata;
public static void main(String[] args) {
Scanner in=new Scanner(System.in);
chars=new ArrayList<String>();

[code]....

View Replies View Related

Checking If Input Is Digit?

Sep 28, 2014

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.

View Replies View Related

Day Of Year With Users Input

Apr 8, 2014

I'm doing a problem where I convert users input for the date (MM/DD/YY) into a written out date and year. That part is fine. The part I'm struggling with is then indicating what day that is in that year. how to use the user inputted MONTH, DAY, and YEAR to then get the day of year.

import java.util.Calendar;
import java.util.Scanner;
import java.util.regex.MatchResult;
import javax.swing.JOptionPane;
public class ConvertDate {

[code]...

View Replies View Related

Java Programming To Input Number And Display All Its Prime Digit?

Jan 9, 2015

I am new to java programming and using bluej for programming and i have tried this question what i have have given in title ... how to find out the errors in the following program:-

class Primedig {
public void getinput(int n) {
int ctr=0;
while(n!=0) {
int r=n%10;
for(int i=1;i<=r;i++)

[code] .....

output:-

For example input is 243 the output comes only 3 not 2& 3 both.

View Replies View Related

Prompt User To Enter Integer From 1 To 15 And Displays A Pyramid

Jun 1, 2014

The exercise sounds like this : Write a program that prompts the user to enter an integer from 1 to 15 and displays a pyramid , as shown in the following sample run (my code displays correctly the first 9 lines):

1
2 1 2
3 2 1 2 3
4 3 2 1 2 3 4
5 4 3 2 1 2 3 4 5
6 5 4 3 2 1 2 3 4 5 6
7 6 5 4 3 2 1 2 3 4 5 6 7

The problem is when i input a number greater then 9 as it requires 2 spaces . I m pritty sure i solved it incorrectly or at lost not optimal as i m using a string that decreases on each line to create the pyramid effect.

import java.util.*;
public class C5_17 {
public static void main(String[] args){
Scanner input = new Scanner(System.in);
System.out.println("Enter the number of lines: ");

[Code] ....

View Replies View Related

Getting User To Enter Integer (registration Number) Between 500 And 5000?

Jan 6, 2014

I am trying to get a user to enter an integer (registration number) between 500 and 5000. if it is below 500 and over 5000 the user should get a prompt "invalid number" and "non-numeric character". See my code below. it is not working when i enter invalid numbers.

import java.util.*;
public class Infomation{
public static void main(String args []) {
Scanner in = new Scanner(System.in);
System.out.print("Student Number:");
int sn=in.nextInt();

[Code] ....

View Replies View Related

Program That Allows User To Enter Up To 10 Integer Grades Into Array

Apr 30, 2015

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 ;

View Replies View Related

Java Program That Randomly Generates Five-digit Lottery Number And Prompts User For Input

Sep 25, 2014

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.

and here is my code. I cant get it to print the right statements.

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) {
//code for determining the prize comparing (g1, g2, g3, g4, g5) to (u1, u2, u3, u4, u5)
if (u1 == g1 && u2 == g2 && u3 == g3 && u4 == g4 && u5 == g5)

[code]....

View Replies View Related

Get Array Elements To Print Out Using Users Selection / Input?

Nov 20, 2014

im trying to make a small program where the user enters their selection choice and it prints out the corresponding information. for example, if they choose "3", i want "3. Soup de Jour" to print out

import java.util.Scanner;
public class rest
{
public static void main(String[] args)

[Code]....

View Replies View Related

JTextfield And Jtable - Get Users Input From Field To Table

Sep 13, 2014

I have project to get from users input like name,surname,to save to Jtable,i have table and jtextfiled but when user get input they don t save to table here is my code:

 Project.zip (33.54K)

public class Projektni extends JFrame {
public final JTextField ime = new JTextField(10);
public final JTextField prezime = new JTextField(10);
public final JTextField index = new JTextField(10);
public DefaultListModel podaci = new DefaultListModel();
public JList lista = new JList(podaci);
String kolone[] = {"ID","Name","Age"};

[Code] ....

View Replies View Related

Adding Textbox For Users To Input Text Onto JFrame

Apr 2, 2014

I need adding a textbox for users to input text onto my JFRame. Also how come the

frame.add(o);

is getting an error under the "add".

Main method class:

import javax.swing.JFrame;
 public class main
{
public static void main(String[] args)
{
JFrame frame = new JFrame();
bot o = new bot();
 
[Code] ......

Other class (this is where I want the textbox to be)

import javax.swing.JTextArea;
import javax.swing.JTextField;
public class bot {
int x;
int y;
JTextField f = new JTextField();
JTextArea a = new JTextArea(30, 50);
}

View Replies View Related

Allow User To Enter Roman Numeral And Then Outputs Integer Number Value - While Loop

Feb 7, 2015

Write a program called RomanNumeralHelper that allows a user to enter a roman numeral and then outputs the integer number value. Use a Scanner to accept command line input from the user and continually ask for a roman numeral until the user enters Q (or q) to stop. Your solution should NOT use a switch statement.

Here is sample input / output:

Enter a roman numeral [Q | q to quit]: III
>> 3
Enter a roman numeral [Q | q to quit]: IV
>> 4
Enter a roman numeral [Q | q to quit]: V
>> 5
Enter a roman numeral [Q | q to quit]: Q
Good Bye!

This is what I have so far in my code, but I cant get what the user inputs when I want it to output the number.

import java.util.Scanner;
public class RomanNumber4
{
public static void main(String[] args) {
// obtain input from command window
Scanner input = new Scanner(System.in);
 
[Code] ....

View Replies View Related

Write A Program That Asks Users To Input 5 Test Scores

Apr 22, 2015

Write a program that asks the user to enter five test scores. The program should display a letter grade for each score and the average test score. Write the following methods in the program:

calculateAverage This method should accept five test scores as arguments and return the average of the scores. determineGrade This method should accept a test score as an argument and return a letter grade for the score, based on the following grading scale

Score Letter Grade
90-100 A
80-89 B
70-79 C
60-69 D
Below 60 F

double test1,test2,test3,test4,test5;
double average;
char grade;

Scanner keyboard = new Scanner(System.in);

System.out.println("Enter the first score");
test1 = keyboard.nextDouble();
System.out.println("Enter the second score");
test2 = keyboard.nextDouble();

[code]....

View Replies View Related

How To Accept Enter As Empty Input

Nov 8, 2014

How can I get enter(return) as empty input from user?!

scanner.next will wait until I input a string ...

But I want it when I hit return sets the variable to empty string ...

View Replies View Related

Quiz Program - Removing Enter Key Space After User Input

Oct 20, 2014

I am writing a short quiz program, and when the user inputs their answer they hit the enter key (the are int). But the last question on my quiz is asking the user to they want to repeat the quiz, but when I run the program, it won't allow me to input any information. I can briefly remember my lecturer saying something about entering in a code after each int the user inputs but I can't remember what it was.

Here is a snippet of my code:

//Question 3
do{
System.out.println("Question 3- What Hollywood actor did Mila Kunis have a baby with recently?");
System.out.println( question3 + ".Ashton Kutcher 2.Bradly Cooper 3.Leonardo Dicaperio h.Get a hint");
answer3 = stdIn.nextInt();
if(answer3 != question3)

[Code] ....

View Replies View Related

Averaging Grades Program - Take Input From User Until They Enter Negative Number

Feb 2, 2015

Ok so I have my program working for the most part. In this program I am supposed to take input from the user until they enter a negative number and that works, the problem is that it doesn't work if I enter a negative number on the first prompt. For example if I enter a 100 it would prompt me again and if I enter a negative number it would quit and give me the average, but if I enter a negative number the first time I am prompted the program just gives me an error. How do I fix that?

import java.util.List;
import java.util.ArrayList;
import java.util.Scanner;
public class Application {
public static void main(String [] args){
Scanner input = new Scanner(System.in);
List<Integer> grades;

[Code] ....

View Replies View Related

How To Check Input Is Integer In Java

Dec 18, 2014

I have to ask how many children's tickets you want to order. When I apply the code below, it just accepts whatever I input, including letters. I imagine it is to do with setting childrensTickets = 0? If I input a letter using the below it accepts - shouldn't it print the error given the input is not >=0?

System.out.print("How many children's tickets do you require? ");
int childrensTickets = 0;
boolean validChildrenValue = false;
while (validChildrenValue == false) {
if(aScanner.hasNextInt()) {

[Code] ....

View Replies View Related

How To Use Regular Expressions For Integer Input

Jul 21, 2014

I have a program in which I take some characters input from User

using
String inputString=in.next();

How can i restrict user that input should be only char 0 or 1?

If the answer is regular expressions then What Should be Its Regular expressions?

View Replies View Related

JTextField That Accept Only Integer Input?

Jul 5, 2014

I have a GUI with a JTextField. I need to check that the input entered by the user is made up of only integers.

For example I accept: 1, 10, 530, ...

I do not accept: -10, 1.5, -6 ...

I would like to implement this control by using a regular expression so I would have a code like that.

JTextField text = new JTextField();
String input = text.getText();
boolean bool = checkInteger(input);
if(bool)
System.out.println("Ok");
else
System.out.println("Error");

The checkInteger(String input) method should check if the input string is correct or not.

How can I do to implement this control with regular expressions?

Is there an easier way to do it?

View Replies View Related

Checking To See If Input From Scanner Is Integer

Jun 12, 2014

So I clipped this out of my Jeopardy game code and made it into its own project for testing. using this code I want to check to see if the input for wage is an integer?

import java.util.Scanner;
public class test {
/**
* @param args
*/
public static void main(String[] args)
{
Scanner input = new Scanner (System.in);

Obviously right now if you enter "aflwkj" or some such for the wager, the program terminates. How to make a loop that will keep asking the user for a value for wage until the input is an integer?

View Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved