I am trying to create a program for my class that requires the input of a letter and the output of whether or not it is a vowel or a consonant. I am using eclipse, it is giving me no errors, but when entering the letter i get an error in the console
import java.util.Scanner;
public class w0571505_a2a {
private static Scanner a;
public static void main(String[] args) {
// enter letter
System.out.println("Enter a Lowercase Letter");
This is a program to input a sentence and print the words that start with a vowel.......There is no syntax error but on executing and typing the sentence and pressing enter,I get a error saying :
java.lang.StringIndexOutOfBoundsException: String index out of range: 0 at java.lang.String.charAt(String.java:658) at sentence.main(sentence.java:22)
Example : I have code and name but my code must start with the first letter of the inputed name if the 2 input is match it will be inserted into database
code = "A"001 name ="Angela" = success this will inserted into database
else
code ="B"002 name="Angela" =failed this will not inserted into database
else
code="A"003 name="Andy" =success still accepts the input cause they have diff code number
What I am thinking on this was compare the code the name? if == it will be inserted but how do i get the 1st letter of the input name?
The code is supposed to output a word from a sentence(from a sample file) with most frequently occurring letter in that word.
Example input: "Therefore, it is this word."
output: therefore
It currently uses 3 loops nested loops, is there a way to improve this?
public static String findWord(String file) throws IOException { BufferedReader in = new BufferedReader(new FileReader(file)); String text, correctWord = null; text = in.readLine(); StringTokenizer tokens = new StringTokenizer(text.toLowerCase(), " ,.?"); //split string into tokens of words only int count = 0, numLetter = 0;
I am trying to write a program that will generate a QR Code from an input text and also display some information about the input/output bits. So far I have created the frame and what to do next. And I'm not sure if I am on the right track since my level of programming is not that great. By the way, I am using zxing libraries from GitHub. I know, there are plenty of generators online for the QR Code, but that is not what I am looking for. As you can see on the attached image, I am more interested in the efficiency of encoding 2D data. Also, I noticed that almost all the online projects regarding 2D codes are for Android. Which is not very useful.
Alright so I wrote a switch statement that decides what range to print based on the letter grade input.
import java.util.Scanner; public class SwitchPractice { public static void main(String [] args) { Scanner scan = new Scanner(System.in);
[code]...
It works fine, but once it the user enters a letter grade and then displays the value, it does not prompt the user for another letter grade so that it can perform the output again. Also if I wanted to display an error message to the user if they enter an invalid letter grade how would I do that. I tried using a while loop and if statement in the switch statement but that didn't work.
I have a problem with functions connected to strings.
I have a random String, e.g. "Hello World!" and I have to change every capital Letter into a small letter and vise versa. This alone would be fairly simple, but I have to do it with two other strings.
lowercase= "abcde...z" and
uppercase="ABCDE...Z". Every small letter stands at the very same position as the capital letter, but in the other string.
There should be a letter for letter search in lowercase and uppercase for the letters of "Hello World".
How I could solve the task, however I need a way to search the first string, here "Hello World", according to position. A statement which does: "Give me the letter of position x". This found letter should be able to be stored in a variable or else be able to be used by another statement. And it should be compatible with a for lope.
Write a program that continuously asks for an alphabet letter, and stops when a non-alphabet letter is entered. Then output the number of upper case letters, lower case letters, and vowels entered ....
How would I display certain output text if the text entered equaled "text".
So lets say you enter a question into a JTextField. You press a button that submits the text. The output displayed depends on what the question you asked was.
Think about it as "If question = What color is the sky? On submit, display text "Blue". How to implement this.
What are formatted input & output in Java? I want to know the difference between general "input & output" & "formatted input & output"? And what is the reason of the naming it as formatted.
Here is my code so far. I am trying to get the WHILE LOOP to work so the user inputs a number, the if statement prints the output and then it returns to ask for another number and goes again and again looping :
import java.util.Scanner; public class ifwhileloop { static Scanner sc = new Scanner(System.in); public static void main(String[] args) { double nmbr;
I want to do basic input/output using Process class. I basically wish that, I should ask user his name and when user provides his name then I would print "Hello '[name]'"
import java.io.*; public class ReadAndPrintName { static Process p;
I am trying to write a program in Java that uses threads.Below is the program requirements:The goal of this assignment is to create a routine which creates multiple threads, has them do work in parallel, and terminates when the last thread has finished.
The Scenario: There are several groups of people in a bar watching the Olympics cheering for their country. Each group will cheer for their country some given number of times, with a random pause (between 2 and 5 seconds) between each cheer. There is enough room at the bar for up to ten different groups to sit (each would be cheering for a different country).
The Program: The task is to write a program that will simulate these cheers using threads. The program should be called cheer.X (X being the language of choice). You may use any language that supports threading. When the program is run it should ask for the number of countries and then the name and how many times it will be cheered for. The main function will then create a thread for each team and each thread is responsible for cheering the specified number of times for the correct team at the random interval. You will submit the proper source code file for me to open and compile myself, not an executable.
An example run would look something like this: How many countries are supported at the bar? 3 Enter the first: China How many cheers? 2 Enter the second: USA How many cheers? 4 Enter the third: Russia
package core; import java.util.ArrayList; import org.lwjgl.input.Keyboard; public class Input{ public static final int num_key = 78; private static ArrayList<Integer> currrentkeys = new ArrayList<Integer>(); private static ArrayList<Integer> downkeys= new ArrayList<Integer>(); private static ArrayList<Integer> upkeys = new ArrayList<Integer>();
I am trying to learn how to use file input/output in addition to exception handling... The problem is my textbook wrote this chapter for a version of Java that hasn't come out yet, so everything I do "according to the textbook" doesn't work. any feedback on correcting these exception errors because I am not sure what is causing them or how to fix them.
I was able to have it display the name of the book in the Book.txt file, but when I added the second part if the file doesn't exist, that's when the errors came up and it wouldn't compile.
import java.io.*; import java.util.*; public class DisplayBook { public static void main(String[] args) { try { File book = new File("Book.txt"); FileInputStream in = new FileInputStream(book);
[Code]...
These are the compilation error messages I am receiving: (I have managed to get it down from 7 errors to just 4, but now I'm stuck)
DisplayBook.java:15: error: unreported exception IOException; must be caught or declared to be thrown while ((letter = in.read()) != -1) //if file exists, displays book title ^ DisplayBook.java:24: error: unreported exception FileNotFoundException; must be caught or declared to be thrown
I'm using one method to take input from the user and append some text to it, then I am trying to return the value of the variable and use another method to print it out. But for some reason whenever I try doing this I can't print out anything and I only get a "null" output. Why this is happening?
package Homework3; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class Homework3 {
I am stuck on one of the projects: Area Calculator
I am able to code an area calc that works, but am unsure how to move all the input/output to main like the project wants. here is a piece of my code so far:
I have the same thing for rectangle, square, and circle (of course with the correct formulas) and the program works perfect, but the assignment is still wrong until I can move the input/output to main. what do I do?
Using JOptionPane,ask for 10 numbers from the user.Use an array to store the values of these 10 numbers.Output on the screen the number with the greatest value.
I had to make a program that allows the user to enter 3 sides and it should output "invalid" if it does not make a triangle and if it does make a triangle it calculates the area of the triangle and it doesnt seem to do anything but say "invalid" as the out put.
import java.util.Scanner; public class MyTriangle { public static void main(String[] args) { Scanner input = new Scanner(System.in); boolean valid = true; double side1, side2, side3, area, A;
import java.util.Scanner; public class Practice { public static void main(String[] args) { //get user input Scanner user_input = new Scanner(System.in); System.out.print("Enter a number: " );
Write a program that prompts the user to input an integer and then outputs both the individual digits of the number and the sum of the digits.
Now I have a code for spacing out the integers, and I have a separate code for adding the digits. But I am not sure how to merge them together. Both of them work independently
Spacing code: import java.util.*; public class SumoftheIntegers { static Scanner console=new Scanner(System.in); public static void main(String []args) { int num1, test, rem; int counter = 0;
[Code]...
Now the sum of the integers code:
import java.util.Scanner; public class sum { public static void main(String[] args) { // Create a Scanner Scanner input = new Scanner(System.in); // Enter amount System.out.print("Enter an integer: "); int integer = input.nextInt();