I'm new to Java and am trying to create a simple payroll program that uses a while loop to repeat until the user enters "Stop" for the employee's name. I've tried everything I can think of and everything others have suggested and for some reason, I cannot get the program to differentiate between the word "Stop" or any other word. what I'm doing wrong? My code is as follows:
import java.util.Scanner; // imports scanner class for user input
public class Payrolltest {
public static void main( String[] args )// begins execution of program {
Scanner input = new Scanner( System.in ); // creates a scanner to obtain user input
String Employee = "name"; // employee's name
how to use the CTRL-D in my program. The program records the amount of times a positive and negative integer is typed. When the user decides to end the program, they will use the CTRL-D to terminate the program. After the button combination has been pressed, I spit out to the user the results. The problem is when I press CTRL-D the program just terminates and I can't even get it to read the next line of code. ....
Write a java program that will ask a user to input grades until the user inputs the sentinel value -1. The program should test each input to determine whether 0<=grade<=100. If the grade entered is within this range, the program should print "Grade accepted;" if not, the program should print "Invalid input".
why this switch code does not work for the 'Q'. Everything works fine for the other cases, i.e. 1,2,3, and 'q', but when I type in 'Q', I get the default case. Please note all the values have been defined in an earlier part of the code but for simplicity's sake I have removed them below
do { switch (choix) { //demande le nombre de patons a achete case '1':
I'm doing a problem where someone will input a name and it will show their title or vice versa. It works fine when the user inputs the name but whenever they input a title it is coming back not found. Not sure what I did wrong.
import javax.swing.*; import java.awt.*; import java.awt.event.*; @SuppressWarnings("serial") public class JEmployeeTitle2 extends JApplet implements //class extends JApplet and AL. ActionListener
(Count positive and negative numbers and compute the average of numbers). Write a program that reads an unspecified number of integers, determines how many positive and negative values have been read, and computes the total and average of the input values (not counting zeros). Your program ends with the input 0. Display the average as a floating-point number.
I moved the different boolean statements around, but I'm not getting the sentinel value to end the run. It continues to let me add integers endlessly. The code I wrote is below:
package exerciseFourOne; import java.util.Scanner; public class AverageOfIntergers { public static void main(String[] args) { // TODO Auto-generated method stub int positive = 0; // number of positive integers int negative = 0; // number of negative integers int sum = 0; // value of sum of integers
The program is supposed to print all even and odd numbers between 50 and 100 using ONE while or do while loop. The evens work, but the program terminates after printing 51 for the odds, which doesn't satisfy the second value sentinel value for the while loop.
public class EvenOdd { public static void main(String args[]) { int x = 50; int y = 50; int i = 0; int j = 0; System.out.print("Even numbers between 50 and 100: ");
I was tasked to make a program that took a string input, then reversed it using recursion. I'm getting a syntax error causing an exit code 1. Also, I'm sure there may be an error in the code as I'm not very strong with recursion.
import java.util.Scanner; public class StringReverser { public static void main(String[] args)
I am trying to create a fortune teller and everything is running fine except the program does not prompt you to answer the questions
Do you like donuts? and What did you have for breakfast?
Here is the code this is in Bluej :
import java.util.Scanner; public class FortuneTeller { public static void main(String[] args) { Scanner keyboard = new Scanner(System.in); System.out.println("Welcome to Fortune Teller");
The program is a Random String Generator; it takes user input (type of string, and length), and then generates a string with their requested method. Its extremly simplistic, but had some interesting coding challenges considering I only just did 'Hello World' a few days back xP I actually already have quite a few additions and modifications I want to make to it, but wanted to get a bit of feedback on it otherwise.
The Main Class, RandomStringGenerator.java:URL... InputHandler.java:URL.... RandomGenerator.java: URL....
I have to write a program that asks the user to enter the name of their favorite city and use string variable to store the input. The program should display the following:
-The number of characters in the city name -The name of the city in all uppercase letters -The name of the city in all lowercase letters -The first character in the name of the city
However, I can't seem to get past the following errors;
Programming Challenge #12.java:37: error: variable cityFirstChar is already defined in method main(String[]) char cityFirstChar = city.charAt(0); ^ 8 errors[CODE ----jGRASP wedge2: exit code for process is 1. ----jGRASP: operation complete. [/CODE]
My code is as follows:
import java.util.Scanner;
/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */
So basically I have to create a java program that accepts a string and does the following:
1.) Insert a blank space before capital letters 2.) Convert any capital letters into lower case except the first letter(if it is capital).
So if the user enters "HiMyNameIsJohn", the result should be "Hi my name is john". I am having problems inside my changeMe method. Everything works fine including putting a blank space in between upper case words. So from the previous example, my code would show "Hi My Name Is John". I am having issues making the code to convert the upper case letters into lower case. Im pretty sure the code should be right after the str.insert(i, " "). But I do not how to code it. Ive thought about Character.toUpperCase(ch); but doesnt work.
Java Code:
import java.util.*; public class WordSeparator { public static void main(String[] args) { String word1, word2; Scanner userInput = new Scanner(System.in);
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.
My Computer Programming teacher has given the class a problem that requires the use of var.charAt(), var.length() and while/for. Basically, the problem is that we have to create program that'll show a mirrored or reverse version of the entered word. Like for example, if your input is the word "Hello" (the quotation marks aren't included), the output will be "olleH".
Here's the code:
import java.io.*; public class StringMirror {public static void main (String [] args) throws IOException {BufferedReader scan = new BufferedReader (new InputStreamReader(System.in)); String enteredWord = ""; int lengthOfTheWord = 0; int lengthOfTheWordMinusOneVersion = 0;
[code]....
It is working, but the problem is that after the output, there's this error that says String index out of range: -1.
the program is working but I kind of wanted it to have no errors in the end.
1. The words remain in their places but the letters are reversed. Eg I love you becomes Ievol uoy 2. The words are also reversed. Eg I love you becomes uoy evol IWrite a program that use the java String class methods.
I wrote a program to read a .txt file and return how many times a, e, s, and t occur in the .txt file. I am getting an error that I do not know how to fix. It says Error: FileNotFoundException cannot be resolved to a type...
import java.util.Scanner; import java.io.File; import java.io.IOException; import java.io.BufferedReader; public class Count { public static void main (String[] args) throws FileNotFoundException { String phrase; // a string of characters
Write a GUI program to convert all lowercase letters in a string to uppercase letters, and vice versa. For example, Alb34eRt will be converted to aLB34ErT.
Write a java program to accept a string, float and an integer as command line arguments. String value should be displayed. Also the program should display the maximum value of two numbers. Use Integer.parseInt() and Float.parseFloat()
I need to design, implement, and test a program to input and analyze a name. The program begins by retrieving a user input string from the keyboard. This string is intended to be the user's name. These are the errors we have to search analyze the user input for: No blanks between names firstName and lastName, Non-alphabetic characters in names, Less than two characters in first name, and Less than two characters in last name. Each of these errors must be thrown. All exceptions must be derived from a programmer-defined class called NameException. Each exception should use a detailed message to differentiate among the file types of errors.
This is the format of my NameException class, is the format itself correct? I will fill in the details of each exception I am just wondering if that is how I should set it up.
public class NameException extends Exception { private String firstName, lastName; public NoBlanksException(String firstName,String lastName) { } public NonAlphabeticalCharactersException(String firstName, String lastName) {
[Code] .....
I was told not to try and catch thrown errors in the main method, would I just create another method in the Driver class to take care of that then?