Main Method Returned To Earlier If Statement
Jun 10, 2014
This program should display the sum, average, product, smallest and largest of the numbers.
Java Code:
//Displays the sum, average, product, smallest and largest of the numbers
import java.util.Scanner;
public class Practice6 {
public static void main( String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("Enter an integer: ");
[Code] ....
The problem is when I enter
The first integer: 7
The second integer: 5
The third integer: 9
The program displays "The third integer is the largest and the second integer is the smallest" then displays "The first integer is the largest and the second integer is the smallest". The main method returned to the IF statement in the line 23. How or why?
View Replies
ADVERTISEMENT
Oct 30, 2014
Alright, I don't understand how to link my compress method to my return statement method "getPText". Also in my compression I only want it to compress for 3 or more consecutive letters.
import java.util.Scanner;
class RunLengthCode {
String pText;
String cText;
void setPText(String PText) {
pText = "";
}
[Code]...
View Replies
View Related
May 27, 2014
I'd like to know how to return a new array, I wrote in a method below the main method. I want to print the array but system.out.print doesn't work for arrays apparently. What structure i should use?
View Replies
View Related
May 27, 2014
I have to write a method called censor that gets an array of strings from the user as an argument and then returns an array of strings that contains all of the original strings in the same order except those with length of 4. For example if cat, dog, moose, lazy, with was entered, then it would return the exact same thing except for the words with and lazy.
Currently, my code so far just prints [Ljava.lang.String;@38cfdf and im stuck.
import java.util.Scanner;
public class censorProgram {
public static void main (String args[]){
Scanner input = new Scanner (System.in);
System.out.println ("How many words would you like to enter?");
int lineOfText = input.nextInt();
[Code] ....
I have to make new string array in the method and return words without four letters in the main method
View Replies
View Related
Feb 13, 2014
I am just trying to test this array, for a locker combination program that involves classes...but the array is printing out the whacky numbers for the location. When I try to call the method in the main, it does not work. How do I call a method that exist within a class into the main method?
public class locker {
public static void main(String[] args) {
CombinationLock();
[code]....
View Replies
View Related
Jan 13, 2014
Here's a class called Fibonacci
Java Code:
public class Fibonacci {
public static int fib(int n) {
if (n < 2) {return n;}
else {return fib(n-1)+fib(n-2);}
[code]....
it contains one method called fib() and one main method.If I would want to have the main method in another class than fib(), how would I write the two classes? Only cutting the main method from this class to another one doesn't work.My question is, is the reason it doesn't work because I then would have to have a constructor in the Fibonacci class, and create a Fibonacci object first which I then use the method on?
View Replies
View Related
Apr 2, 2014
I'm making a Hangman program for Java, here's my code:
import java.util.Scanner;
public class Hangman {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
String answerWord = WordList.getWord();
[Code] .....
The Compiler gives me this only error:
Hangman.java:39: error: unexpected type
displayWord.charAt(i)=userInput.charAt(0);
^
required: variable
found: value
I understand that charAt returns i as a value and not a variable. What do I use to return a variable as I intended?
View Replies
View Related
Dec 6, 2014
I am trying to get the program to ask the user to enter the project grade and if it is less than 65, then I want the program to display "fail" or if it is greater than 64 than I want it to display "passed". In this project I have to include a method and I am trying to call it in my if-else statement. I keep getting an error message saying "Project.java:143: error: incompatible types: void cannot be converted to int". I posted my code below. It's a long program, but this part is toward the bottom.
import java.util.Scanner;
public class Project {
public static void main(String[] args) {
//call method
welcomeMessage();
[Code] ....
View Replies
View Related
Apr 2, 2014
Im having trouble with my method return. I am new to using methods and cant seem to grasp the idea on the return part. I have to write a method that tells if a number is prime or not. This is what I have so far and it wont compile because it is saying "missing return statement } "..
import javax.swing.JOptionPane;
public class IsPrimeMethod
{
public static void main(String []args)
{
String primeNum;
int number;
int i = 2;
[code]....
View Replies
View Related
Sep 29, 2014
Okay i have done some research and have found that when using the JOptionPane, when the cancel or x button is clicked, the value is returned as null for the particular JOptionPane. It does not seem to work when I try to code it though, I have tried the following:
Java Code:
public static int getBoardType()
{
int boardType = 0;
String boardInput;
boardInput = JOptionPane.showInputDialog(null,
"Enter 1 (LongBoard), 2 (Shortboard), or 3 (BoogieBoard)." ,
"Dwelling Type",
JOptionPane.QUESTION_MESSAGE);
[Code] ....
If the "X" button or the Cancel button does in fact return a null value, why is the way I have this set up not working?
View Replies
View Related
Jul 23, 2014
I'm trying to make a TBG (Text Based Game) in Java for Android. Now, when I try to run it, it says No Main Method to run this program. The compiler also checks the program and tell me there are no errors.
View Replies
View Related
Jan 1, 2015
class Base
{
public Base rtc() {
System.out.println("am in parent");
return new Base();
}
}
class Ret extends Base
[Code] ....
Output :
I am in child class but b1.rtc requires b2 to hold the return value y not Ret's object.
View Replies
View Related
Jan 21, 2015
I have observed a strange behaviour from Resultset object. My application fetches 400 records from a table and processes these records every 10secs. By default the resultset has a fetchsize of 10 from the database cursor. As I understand if the query returns 400records, the resultset will fetch 40times, in multiple of 10 to get all these 400 records from database cursor.
Query : SELECT * FROM ( SELECT * FROM TestTable
WHERE STATE_ACTION = 0 ORDER BY ROP_TIME DESC )
WHERE ROWNUM <= 250
Observation : Under a normal operation, the resultset fetches all the 400 records on query execution from database cursor, but under unknown conditions the same resultset object fetches only 10 records from the database cursor and exits. Please refer page 297 in document below for the result fetch size details. JDBC developer guide for oracle 10g : [URL] .... This condition self-heals itself in few hours or restarting the database or restarting the server. The root cause of this behavior is unknown.
View Replies
View Related
Oct 1, 2014
in java why main method is always static in nature...
View Replies
View Related
Jan 26, 2014
The idea is to create a program to add plants and retrieve plants from a Nursery. I created a class with the properties of the plants and also there is the class an Array list to keep track of the plants entered ( they will have to be printed later) (I am not too sure if adding a public class there is the best option.
The program will allow the user to pick and action and from there the code will do something. I don't want to have all the code inside 'main' The problem is in line 114.This is what I have so far.
Java Code:
package plant.nursery;
import java.util.ArrayList;
import java.util.Scanner;
/**Class to create a plant for a nursery.
public class PlantNursery
[code]....
View Replies
View Related
Apr 26, 2014
this is my program error occured run time,but compile sucessfully
{error msg-Error: Main method not found in class helloworldapp.HelloWorldApp, please define the main method as:
public static void main(String[] args)}
class HelloWorldApp
{
private int empno;
private float salary;
void setHelloWorldApp()
{
empno=12;
salary=1200;
[code]....
View Replies
View Related
Nov 17, 2014
I'm trying to call a method to my main method, but I can't seem to get it to work and it keeps resulting in a compile error.
import java.io.*;
import java.awt.Point;
import java.text.DecimalFormat;
import java.util.Random;
public class Chase {
public static void main(String args[]){
[Code] .....
View Replies
View Related
Sep 10, 2014
I have been reading about methods and I do have a beginner level understanding on how they work. I was trying to mess around and make a dog calculator using methods. I ran into a small snag; I cannot get the method to call to the main or the program to compile correctly. The first code below is the original. To me it looks like (based off of some examples I looked at) there should be no problems, but NetBeans gives me a few errors. 1) line 8- "cannot find symbol, variable dogYearCalc; 2) line 18 illegal start of expression; and 3) line 22 - unreachable statement.
import javax.swing.JOptionPane;
public class KrisExample {
public static void main (String[] args) {
double dogYears = 0;
JOptionPane.showInputDialog (null,"Please enter you dog's age in human years:");
[Code] ....
Someone told me that I was calling dogYearCalc without any arguments in your main method. I take that to mean that I needed to add it to the main, so I did here:
public static void main (String[] args, double dogYearCalc) {
That got rid of my first error, but then when I tried to run the program NetBeans said that I have no main class, so switched back to the original program above.
I thought that when I calling the dogYearCalc method on line 10 was the whole purpose of using a method. It seems to me that putting it somewhere in the main is counter productive.
View Replies
View Related
Jul 28, 2014
Can we recall the main method? I'm trying a code to recall main method (after the calling of JVM). I know this doesn't make any sense but I'm trying this just like that.
Code:
class derived {
public static void main(String args[]) {
System.out.println("Main Method class");
show();
}
static void show()
[code]....
View Replies
View Related
Jan 29, 2014
I've written a program just for the sake of it (to learn) and it seem's like theres quite a lot in the main method that perhaps could be split up into seperate classes. I'm not too sure where should start with this though, or what my thought process should have been as I was writing the program.
import java.util.Scanner;
public class Loops {
public static void main(String[] args) {
int answer = 16;
Scanner scan = new Scanner(System.in);
// Question
System.out.println("What is 4 x 4 ?");
[code]...
--- Update ---
here's a version without code comments as they might make it harder to read here -
import java.util.Scanner;
public class Loops {
public static void main(String[] args) {
int answer = 16;
Scanner scan = new Scanner(System.in);
System.out.println("What is 4 x 4 ?");
int userAnswerInt = 0;
[code]...
View Replies
View Related
Jan 7, 2014
What does void and static mean in the main method?
View Replies
View Related
Nov 1, 2014
I was reading the book, "Head First Java" and it was talking about how there may be multiple classes in a large application, but there will be only one main method.how does it work that way? How can you have multiple classes, but only one main method?
View Replies
View Related
Feb 9, 2014
This time I have to make a Black Jack game ( I guess this is a classic) I have created Three classes for this BlackJack( Main), Card, and Player.
What I am trying to do is put the Give one card to the player and remove it from the deck into a separate procedure because I will be doing this several times during the game.
This is the code I have so far Under the class BlackJack.
Java Code:
package black.jack;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Scanner;
[Code] .....
View Replies
View Related
May 7, 2015
I can call a child method from a main method. If I have a parent called "Assessment", a child called "Quiz", and another child called "test". Can I instinate an object like Assessment a = new test(); and call a method in test.I know the method can be called if I instinate the test t = new test() but that defeats the purpose of inheritance which I'm learning in class.
View Replies
View Related
Oct 26, 2014
When I try to call an object it can't find the symbol in the argument list. NetBeans says that it cannot find the movieCategory symbol when I try to call it. When I compile it to test a popup comes up that states "One or more projects were compiled with errors. Application you are running may end unexpectedly. I ran it anyways and everything runs up to the point of where it should call the object.
At this point it should get the Movie object and run the code within that, but if I put one of the categories it throws. "Exception in thread "main" java. lang.RuntimeException: Uncompilable source code - Erroneous tree type: <any>at MovieApp.main(MovieApp.java:33)Java Result: 1"
From my understanding to call an object it requires objectName.methodName(argumentList). Here is my Main method
/**
*This application will store a list of 100 movies and display them by category
*/
import java.util.Scanner;
public class MovieApp
{
public static void main(String args[])
{
//Displays <code>String</code> welcome message
System.out.println("Welcome to the Movie Application.");
System.out.println("There are 100 movies in the list.");
System.out.println("What category are you interested in?");
System.out.println();
[code].....
View Replies
View Related
Oct 10, 2014
I tried to create a simple program. The main method is supposed to call out the secondary method to use Scanner in order to ask a person to type in a number, which will be assigned to int x. Then the secondary method supposed to return the int x to main method, which supposed to print it out. And for some reason I just can't do it. No matter what the main method refusing to accept the int x.
import java.util.Scanner;
public class Return{
static Scanner newNum= new Scanner(System.in);
public static void main(String[] args){
getInt();
System.out.println(x);
}
public static getInt( ) {
// TODO Auto-generated method stub
int x;
System.out.print("give a num");
x= newNum.nextInt();
return x;
}}
View Replies
View Related