Lexicographic Ordering - When Input String Values / No Output Takes Place
Jan 28, 2015
I have a assignment to do some Lexigraphic ordering. I have figured how to get the majority of this done, however, when I input my string values. No output takes place? :s
import java.util.Scanner;
public class Lab03c {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner lexi = new Scanner (System.in);
String s1,s2;
Write a method called largerAbsVal that takes two integers as parameters and returns the larger of the two absolute values. A call of largerAbsVal(11, 2) would return 11, and a call of largerAbsVal(4, -5) would return 5.
I have tried this code using methods in the Math Class but I am getting an error in Practice-it that says
Line 4 Your method's return type is void, which means that it does not return a value. But your code is trying to return a value. This is not allowed.
cannot return a value from method whose result type is void return Math.max(Math.abs(Num1), Math.abs(Num2));
Here is my code. What I am doing wrong?
public static void largerAbsVal (int Num1, int Num2) { return Math.max(Math.abs(Num1), Math.abs(Num2)); }
But, I coudln't find any place in Java/JSP where the value for status is being set. What could be the possible place where the values for status is being set.
As the code is client specific, so, I couldn't paste the specific code over here but I have searched in whole workspace i couldn't find a single place where values for status is being set/assigned to.
Create a method called mirrorImage, which takes two integer arrays as input parameters. You may assume that the two actual parameters have the same length. Your method should return true if the arrays are the reverse of each other. Otherwise mirrorImage should return false.
Examples:
data1:{1,2,3} data2:{3,2,1} ==> true
[code].....
I'm pointing a place outside of the array or something
I'm trying to make a simple Caesar cipher that takes in a String as the first argument and a integer shift as the second argument. Namely, there appears to be a problem with the loop and how I have declared the array - I want the converted characters to be put into a new array called newCharacterArray, converted back to a String and displayed in the command prompt window.
public class Caesar { public static void main(String inString, int k) { System.out.println("String: " + inString); char inStringArray[] = inString.toCharArray();
I have been struggling with this program for weeks. This program is supposed to take a user's inputted odd number and then print out all prime numbers lower than that number.
public class PrimeNumber { Scanner scan = new Scanner(System.in); int userNum; String neg;
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.
How do I put this code in a way that it works because I know it is probably something obvious but I cant find how to make the array readable without error. It is supposed to intake two values and output what day of the week it is.
Testing Program
Initial day: Monday Next day: Tuesday Next day again: Wednesday Previous day: Tuesday Next week: Tuesday Add 4 days from initial day: Friday
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 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");
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?
it gives me an error at the end class part some syntax error insert "}"..
* Course: IT110 - Introduction to Programming * Filename: MyCustomShirtsPhase1.java * * Purpose: Created a simple online ordering system for My Custom Shirts customers */ import javax.swing.JOptionPane;
i am studying java from head first java book and yesterday i was working on a program called QuizCardBuilder. what i noticed is that when i changed the order of the lines from the book i get a blank frame with nothing on it.this is my code that gives blank frame
public class QuizCardBuilder{ JFrame frame; JTextArea question; JTextArea answer; JButton nextButton; ArrayList<QuizCard> cardList;