1. ask user to input a decimal
2. output 1 - confirms the input
3. output 2 rounds the input value to the nearest integer.
Here is what I have so far:
/*
* 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.
*/
import java.util.Scanner;
public class IT145Exercise13 {
static Scanner console = new Scanner(System.in);
[Code] .....
Results with input of 5.25:
run:
Enter a decimal:
5.25
You entered 5.25
The integer value is 5 YES however,
BUILD SUCCESSFUL (total time: 6 second)
However, if the input is 5.95 here are the run results:
run:
Enter a decimal:
5.95
You entered 5.95
The integer value is 5 Here I expect 6
BUILD SUCCESSFUL (total time: 6 second
Not sure how to ask the output of the variable integerOut to be rounded to the nearest integer?
Write a program that will read two numbers and an integer code from the keyboard. The value of the integer code should 1, 2, 3, 4. If the value of the code is 1, compute the sum of the two numbers. If the code is 2, compute the difference (first number minus second). If the code is 3, compute the product of the two numbers. If the code is 4, and the second number is zero, compute the quotient (first divided by second). If the code is not equal to 1,2,3,4, display an error message. The program is then to display two numbers, the integer code and the computed result to the screen
here is the code that I have so far:
public static void main(String[] args) { Scanner read = new Scanner (System.in); int num1, num2, code, sum; System.out.println("Please enter a number"); num1 = read.nextInt();
I am trying to get this code to round up the average after the user inputs all 3 grades but i cant seem to get printf to work.
import java.util.Scanner; import java.text.DecimalFormat; public class Average { static Scanner console = new Scanner (System.in); public static void main(String[] args) { String studentName;
I need to round my variables to the nearest "tens" place and I'm having trouble doing so. Every time I run the program it comes back with a number ending in .0 even if its something like 11 / 3. How can I fix this?
public static void results(int game, int totalGuess, int best) { double avg = Math.round((totalGuess / game) * 10.0) / 10.0;
The first problem is that the numbers don't round in IntelliJ.
Example: ('s in Dutch) Geef de vorige kilometerstand: 125 Geef de huidige kilometerstand: 900 Geef het aantal getankte liters: 50 Verbruik voor 775km: 6.451612903225806/100km
That 6.4516..... is the problem, how can I make it 6.45/100km?
for standard deviation my output is not rounded to the 10's place, how can I make it round to the 10's place. Here is my code.
import java.util.*; public class chapter7 { public static final int Max_Number_Scores = 100; public static int fillArray(double[] scores) { System.out.print("You entered "); for (int i = 0; i < scores.length; i++) { System.out.print(scores[i] + " ");
I'm currently working on a loan calculator... The only problem I'm having is occasional values that have very long decimals... How do I round the decimals?
I've a question on rounding doubles on 0.05 As far as i know there is no class method that is able to do this. To achieve this rounding i have the following code:
We are in the process of developing a e-commerce application. It is a web site for a book shop. It is a site very similar to Amazon.com where you can order books online. Front end is in Java Technology. There is however a concern about where to put the business logic.
I am suggesting to put all business logic in the Oracle Database, as stored procedures (i.e. packages). However, one of my colleague says that when you call a Oracle stored procedure from Java, it takes 2 round trips, one to validate the procedure and then to validate the input / ouput parameters of the procedure.
In a website application like what we are trying to build, is it sound advice to put all business logic in the DB? Or should it be in the middle tier (app. server) programmed in Java? Or should you spread in between the middle tier and DB? If so how?
public class MyInteger { private int value; public MyInteger(int number){ value = number; System.out.println("Constructor created with value of " + value);
[code]....
I can't seem to get the value for integer1 and integer2 to pass with the setValue method. I get a runtime error stating the I need to have an int value for these two integers.
public class NewClass4 { public static void main(String[] args) { int a = 1; int b = 2; int c = 3; a += 5; b *= 4; c += a * b; c %= 6; System.out.println("a = " + a); System.out.println("b = " + b); System.out.println("c = " + c);
I've made a class called Car with a method which will tell me a category for the engine size regarding the actual size (which I've included in the main just so I could see if it works) but everytime I test it I get an error.
public class Car { public String b; public String c; public double es; public double cs; public String getCategory() { if (es < 1.3)
[Code] ....
Figured it out. Was missing parenthesis on audiCar.getCategory();
import javax.swing.*; import java.awt.*; public class PRJ04 extends JFrame { public static void main (String [] args) { PRJ04 frmApp = new PRJ04(); PanelChart pnlChart = new PanelChart();
[Code] .....
When I comment out the adding and setting of the pnlChart on my main driver, the pnlPopulationInputs shows up fine, and it runs ok. When I add the pnlChart I get errors like crazy and a white screen. My errors:
Exception in thread "AWT-EventQueue-0" java.lang.ArithmeticException: / by zero at PanelChart.drawChart(PanelChart.java:45) at PanelChart.paintComponent(PanelChart.java:24) at javax.swing.JComponent.paint(JComponent.java:1054)
[Code] ....
Once more with this one, I refer back to our in class example. Our programs are set up the same, yet he has no issues with the "/ by zero" exception.
I have done 90% of the coding however i am stuck with producing the output, i just cant get the user fields to show.
I have attached a picture of the output that is required. The program consists of two classes i have attached the database class, and have inserted my coding below.
import java.sql.*; import java.io.*; import java.util.*; public class QueryDB { private Connection con = null; String userID,
I have to create a program that takes a list of student names and grades and then takes the 2 highest scores and reads them, but the result won't show. I'm pretty sure it's because I'm not sure about how to code the last part which should output the results. Here's my code.
import java.util.Scanner; //Reads input and outputs 2 highest scores //for loop. nested for. public class HighestScores { public static void main(String[] args) { //create values String studentName;
I have to get my output to show as per the image attached i am very close but not there yet. I have also attached the database where i extract my information from
/* Program Name: QueryDBDB.java Purpose: to build an initial database for the stocktrakcer application */
import java.sql.*; import java.io.*; import java.util.*; public class QueryDB { private Connection con = null; String userID,firstName,lastName,name,symbol; public QueryDB() throws Exception
i need to seek all data in result set one by one.i excuted a query which i don't know the result of it...it could be have one result in result set or 10 result.i tested this code :
PHP Code:
Query = "select * from book" while (Rs.next)) { row.add(new Book(Rs.getString(i)));
//Book is a class
}
but didn't work. do we have any other way we seek the result set without rs.next() ???
char array[] = new char[10]; int i = 0; array[i++] = (char)('A' + i); System.out.println("char for array is: " + array[0]); mh_sh_highlight_all('java');
However, the result for array[0] is B. Not A. from my understanding, the array[0] should be 'A'.
Right now I have three stacks. Each stack holds characters, with the normal operations of pushing and popping. I am trying to compare two characters from stack1 and stack2(each character is a digit character). I would like to be able to do arithmetic on the digit characters and the push the answer on to a result stack.
Ex.) I pop character '3' from stack1 and '5' from stack2. Then I add the two. equaling '8' and pushing that character on to the result stack. This will hopefully in turn allow me to add arbitrary large numbers that integers will not support.
I am having trouble because I believe I am getting some ascii character values when I pop off the result stack. here is a small piece of my code
public void addition() { char temp1 ,temp2; int i = s1.getSize(); for(int j= 0;j<i;j++) { temp1 = s1.pop(); temp2 = s2.pop(); if(temp1+temp2>=10)
ResultSet rs = result.executeQuery(selectsql); int columns = rs.getRow(); while(rs.next()){
[Code].....
I can print out the result correctly, there are three rows of result from the database, but they are shown in one row on the browser, how could i show the result one row after another to let it looks pretty?