initialize the min and max to be the first numbers entered, need to improve the code, because if the number entered is < 0 there is an error. but i dont understand how i would initialize to the first number entered, my understanding is tha if the user enters a 5 , then i should initialize to value 5, but i cant anticipate what the user will enter. I could initializa to null, but that still is not the first number entered.
int min = 0;
int max = 0;
int option = JOptionPane.YES_OPTION;
while ( option == JOptionPane.YES_OPTION){
This one is working if i set value in fmt but what i want to happen is when i enter a number in textbox it will be fommated on the format that i want, so i think i need to an of og text and set it into value of fmt? <y plan is when I enter a number in textbox it will automatically formatted ....
My program seems to work ok when i enter number in order like 1,2,3 = true , and all the numbers for false seem to be working as well! my problem is when i enter number like 3,2,4 that are not in order but still are consecutive!! I thought that another if statement would be the solution but i have tray several different ones and still can't make it work !!!
Java Code:
import java.util.*; public class Consecutive{ public static void main (String [] args){ Scanner console= new Scanner(System.in); System.out.println("Enter three numbers"); String numbers = console.nextLine();
What I am trying to do here is allow input to loop until 0 is entered for the product number. When 0 is entered, it should then dump the total for each individual product. I've tried it about a dozen different ways and have yet to be able to get the loop to function as intended. The way I have the code below, the loop will not function at all (where as before it looped, but never finished).
import java.util.Scanner; public class Sales { public static void main(String[] args) { double total1=0.0; double total2=0.0; double total3=0.0; double total4=0.0; double total5=0.0; int product;
I have returned with yet another problem but I think this one might be a bit easier to fix.
So the whole MO of this program is to take user input, and display the sum of the digits of the number they entered. I am supposed to do this by utilizing methods. So far this is what I have and when I compile it tells me that it "cannot find symbol", which I don't understand as I define what "m" is in the for loop. The other error is that it says:
"Exercise6_2.java:22: error: incompatible types: possible lossy conversion from long to int return result; ^
I don't understand why it's giving me this error nor do I understand why result seems to inherently be an int. (Also the public static int sumDigits(long n) method was given to me by the book so that is what I am supposed to use).
import java.util.Scanner; public class Exercise6_2 { public static void main(String[] args) { Scanner input = new Scanner(System.in); System.out.println("Enter a integer"); long n = input.nextLong();
Basically i have a question ask me to write a program that read integer from keyboard until a negative number is entered, and then print out the max and min out of the number i have entered.
This is what i have done already which works, but i need to ignore the negative number when print out max and min...which i dont know how to do so. when i compile this program now it will always give me the negative number i enter at the end as minimum. which i need to ignore
Also if negative number is entered at once the program should print a error message say max and min are undefined.
public static void main(String[] args) {
Scanner in = new Scanner(System.in); int large = Integer.MIN_VALUE; int small = Integer.MAX_VALUE; while(true) { System.out.print("Enter a integer: "); int n = in.nextInt();
I'm trying to learn Java and my current project is to write a short program to determine the factorial of a number entered by the user. I haven't looked. There may be a method that will do it, but I want to use a for loop specifically.
What I have compiles just fine. I'm actually pretty thrilled just with that. Here is what I have:
class factorial { public static void main( String[] args) { Scanner scan = new Scanner(System.in ); int num; int product = 1;
I have to store the name SD array and display the room and floor no. whose name is entered but i am having a problem with the logic part. The answer is coming to be wrong
import java .io.*; class hotel { public static void main()throws IOException { InputStreamReader read = new InputStreamReader(System.in); BufferedReader br = new BufferedReader(read); String ar[][] = new String[5][10];
So i'm writing a for loop to convert any number entered to base 10 with any base provided as well. My code does not work because I need a way to reverse the code order, so the new number is printed correctly with the given base. My code so far:
public static void main (String[] args) { Scanner kb = new Scanner (System.in); System.out.print("Enter a number :: "); int numOriginal = kb.nextInt(); System.out.print("Enter a base :: "); int base = kb.nextInt();
[Code] .....
newBase has a problem with how it calculates the new number, looking for correct newBase code for conversion?
I'm working on a program where the user inputs song information (name, artist, filesize, duration) which is stored in a database. Once the user adds a song, the details should be stored in the first empty song slot (4 song slots total) and then taken back to the menu interface.
What I'm having trouble with is that I can add the first song fine (song1), but when I try to add another song, the information entered into song1 is gone. I've worked out that this is because every time I call upon the addNewSong() method, I'm creating four Song objects that are brand new with the line:
Song song1 = new Song(); Song song2 = new Song(); Song song3 = new Song(); Song song4 = new Song();
How to fix this problem is where I'm stuck because if I move these lines elsewhere, I get a 'cannot find symbol - variable song1' error.
Here is my code:
public class SongDatabase { Scanner console = new Scanner(System.in); public void addNewSong() { Song song1 = new Song(); Song song2 = new Song(); Song song3 = new Song(); Song song4 = new Song(); if (song1.isEmpty()) {
What's up with this. Just trying to test my hands on java packages, and had this error(by java) after successful compilation:
Error occurred during initialization of VM java.lang.Error: Properties init: Could not determine current working directory. at java.lang.System.initProperties(Native Method) at java.lang.System.initializeSystemClass(System.java :1119)
Main.java
package com.aceix.simplecalc; import com.aceix.simplecalc.inputhandler.InputHandler; import com.aceix.simplecalc.mathoperation.MathOperation; public class Main { public static void main(String[] args) {
Write a program to input a person''s age and salary, if the age is over 32, add $100 if otherwise subtract $500 from salary, finally output the age and new salary here is my code. I am getting a red line underneath the word 'salary' and i would like to know why and why i have to initialize it. and this is what i have tried.
</Scanner scan = new Scanner (System.in);/> </int age, sum, difference, old_salary, new_salary, salary;/> </System.out.println("Please enter the person age");/> </age = scan.nextInt();/>
The problem is to figure out the number of cartons needed to box up the strawberries picked by the farmer and his wife. The farmer picks 8.4 lbs per hour and the wife pick 10.8 pounds per hour. They pick from 8 am until 4Pm (8 hours). You can put 20 pounds per box.I understand the word problem and how to declare and initialize variables. I'm just confused how to display the math into java to solve it.
After this problem is fixed, my math game will run. The answer variable is supposed to be equal to the cases in the second switch statement by random but I get errors whenever I try to initialize it this way. I have been writing this program for almost 5 days now and it is finally wrapping up. Why I can't map the answer variable to the second switch statement the way I want to?
package pkgnew; import java.util.Scanner; import java.util.Random; public class New { public static void main(String args[]) { //Declare and construct variables Random randomnum = new Random(); int fnum, snum, answer;
I'm trying to make an array of objects, which I then initialize using objects that I have already created. I have main class, a secondary "Other" class, and a third "Other2" class. In the first Other class, I create three objects of the Other2 class, an object array of the type Other2 , and I then try to add the three objects to the object array, which results in the errors:cannot find symbol: class objectArray, ] expected, identifier expected
here is my code:
Other class public class Other { Other2 object1 = new Other2(); Other2 object2 = new Other2(); Other2 object3 = new Other2();
Write a program OutCircle.java that declares and initializes three floating-point variables (r, x, y): the first variable represents the radius r of a circle centered at (0,0) and the second and third variables are the coordinates (x, y) of a point in the plane.Your program should print true if the point is outside the circle and false otherwise. Hint: A point is outside the circle when its distance to the center is greater than the radius.
I am trying to use a custom listener to initialize database connection pool (C3P0) on start up and then destroy on context shut down. The reason for that is that I whenever context is shutdown I have a memory leak because initialized connection pool is not being destroyed.
I have a static class called C3P0Utils that deals with connection pool. In my listener in contextInitialized method I have tried at first to init the pool like this :
I know that object is created. I checked it using jconsole. However it is not accessible with in the application. My second attempt was to regester the pool and then add it to the context and then when I need it read from there.
I just can't find a way to check if user puts any input or not? The line is Employee Name and I need to validate that he puts something there.
import java.util.Scanner; public class JavaMartInventorySystem { public static void main(String[] args) { String empName; Scanner keyboard = new Scanner(System.in);
The program to actually read what i am entering inside the comboboxes. It is all there but does not work when i hit the submit purchase button.
import java.util.*; class DateConstructor { /* Verifies that the day code is consistent with monthCode and yearCode. Returns the corresponding date if so. If not, it sets the errorCode to an appropriate value and returns null. */ public static Date constructDate(int monthCode, int dayCode, int yearCode, ErrorCode errorCode) { boolean isCorrect = false; Date dateEntered = null; switch (monthCode)