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;
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) {
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.
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
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'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 {
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.
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):
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: ");
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();
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 ;
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)
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)
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"};
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); }
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);
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
System.out.println("Enter the first score"); test1 = keyboard.nextDouble(); System.out.println("Enter the second score"); test2 = keyboard.nextDouble();
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)
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;
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()) {
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?