I am trying to write a program that will take two inputted numbers (a and b) and determine how many divisions can be done by dividing by b until the quotient is less than b. For example if a=64 and b=2, then you would be able to do:
64/2=32
32/2=16
16/2=8
8/2=4
4/2=2
2/2=1
1<2
so there is 6 divisions.
How would I use a loop to create this type of program?
I've beginning a new assignment and would like some feedback on my outline for the program. You are to design a simple calculator using the stack data structure to perform additions, subtractions, multiplications and divisions. The user may enter an arithmetic expression in infix using numbers, parentheses and arithmetic operations (+, -, *, /). After an expression is entered, its postfix or prefix notation is displayed and then the result of the expression. You are required to design your own infix to postfix and infix to prefix conversions.
The professors example includes: SinglyLinkedList implementation, a Stack that implements Stack interface and extends SinglyLinkedList, a Node class, and StackApp -- in addition to the main class and the prefix/post-fix classes.
(The equation is entered/stored as a string variable) System.out.println("Enter equation: "); equation = input.next(); equation.trim();
(1.) Get the user input: - evaluate the user input and use a stack to determine the correct prefix/post-fix notation. - from the stack, pop each item: a. account for '(' and ')' to push all operators and write all operands until ')', then pop/write b. store new equation into a list (in prefix/postfix notation)
(2.) Display the list in both notations to the user.
(3.) Perform the calculation.Do you think it will be alright to calculate the original equation that was entered? It seems too much to then design a class that will then cycle through the polish notation and calculate according to that format.
I have i am trying to implement tooltip through javascript, like when we click on an image link tooltip should be displayed and it should have close button/ close image to close that tooltip.like the same way i will have multiple images on page, when ever i click on the images all tooltips should be displayed on the page when ever i want to close that then only it should close through close button on tooltip.can we do it through java script or will go for jquery.
I'm very new to Java, and I am creating a program that takes multiple user input to create one face. I have a class for the eyes, nose, lips, and headshape. For some reason, my program is not drawing the graphics. ***for question purposes, I have only included my head shape class and my test class****
my "test" class:
import javax.swing.JFrame; import javax.swing.JOptionPane; import javax.swing.JPanel; public class FaceTest { public static void main(String[] args) { String head = JOptionPane.showInputDialog("Would you like a circle, square, rectangle shaped head?: ");
I'm working on an old site that we have, I'm adding a couple dropdowns to our forms.With a connection to our database I can pull in values for selBaseCurr, But it's not pulling any values into the second dropdown for selTargetCurr...Am I missing something in the while loop?
here I have a do-while loop. When I push a button, then press enter, the program should do stuff, then ask me for another key. If I press any key but q, it repeats itself. If I press q then enter, it should end the loop. But then when I press q then enter, it still does the functions in the do-while loop.
Java Code:
Scanner kb = new Scanner(System.in); System.out.print("Press any key to start."); String letter = kb.next(); do { stuff System.out.print("Press any key to call another number or press "q" to quit."); letter = kb.next(); }while(!letter.equals("q") || !letter.equals("Q")); mh_sh_highlight_all('java');
What I'm trying to do below is to say if (adultTickets > 0) I want to bypass the studentOAP tickets question and go straight to the question about dinner. But if (adultTickets ==0) I want to go to the studentOAP question and then if the (studentOAPTickets >0) to go to the question about dinner. But if the (studentOAPTickets ==0) I want to go straight to the question about the contact number.
System.out.print("How many adult tickets do you require? "); int adultTickets = 0; boolean validAdultValue = false; while (validAdultValue == false) { if(aScanner.hasNextInt())
So the while loop I am trying to use is: while( type != "EXIT" ) { type = input.next(); }
The problem is that typing in EXIT doesn't end the loop like I want it to. I also tried input.nextLine(); but neither of them work. The loop is being used to fill an ArrayList so the number of elements can change based on how many they want. What am I doing wrong, or what alternatives do I have?
how a nested for loop increments the outer loop and then the inner loop and then when it runs the inside code.I've ran the program a few times but I'm just not understanding it, need little narrative to it?
I am learning while loops but the output I am getting is not what I want? My class:
public class BottlesOnWall { public static void main (String[] args) { int x = 99; while (x > 1) { System.out.println(x + " bottles on the wall!");
[Code] .....
The output I am getting is this:
99 bottles on the wall! 98 bottles on the wall! 97 bottles on the wall! 96 bottles on the wall! 95 bottles on the wall!
[Code] ....
I want it to stop on "2 bottles on the wall!" and then print "Only 1 bottle left on the wall!". How do I go about doing that? I have tried different variations of the condition (x>1), I have tried (x>5) but it still goes down to 1 bottle?
I'm trying to make a piece of code that writes a for Loop program using OOP. I need to create a class, name that class and have it contain several reverse methods and use a runner class to test it.So far this is the code I've come up with. Does it work or not?
public class loopDemo{ public static void main(string[]args){ String alphabet = "abcdefghijklmnopqrstuvwxyz"; public String reverse(){ char myBoi; int myIta; String tebahpla for(myIta=25j i>=0 ji++){ tebahpla+= alphabet.charAt(myIta);
I am relatively new to Java and I am only beginning to learn about SQL. I have some basic's down but I have been wondering is there a way that I can add data to my database using loops instead of having to physically code every row/column individually ?
The instructions are to "write a program to simulate tossing a pair of 11-sided dice and determine the percentage of times each possible combination of the dice is rolled... then ask the user to enter the number of sides on a die" The code is all provided here, I just have to put it in the right spots. (Side note, I cannot use arrays.) Here's the original file I was given to work with:
Java Code:
import java.util.Random; import java.util.Scanner; public class DiceProbability { public static void main(String[] args) { //Declare and initialize variables and objects //Input: ask user for number of rolls and number of sides on a die //Print heading for output table
[Code] ....
When I run it, I get something like this (just a part of my output):
Please enter the number of sides on a die: 6 Please enter the number of rolls: 2
public class dowhile2 { public static void main(String[] args) { int i = 1; while(i <= 100){ System.out.println(i); if(i == 50){ break; } i++; } } }
I just want to know how to count this lines of codes. Because if I place for example i++ further up the code or the system.out.println a bit lower the result will be 1-49 or 2-50 and not the goal that is 1-50.
I want to know how to think and count. Why do i get 2345678.........50 and not 12345678........50 or 12345678.....49, thats the question.
I am completing the exercises in Java How To Program 8th Edition by Harvey and Paul Deitel.There are two optional exercises GUI and Graphics Case Study Exercises on page 141 Chapter 4.
I have to use loops and control statements to draw lines thereby creating two designs.I am trying to create the design on Fig. 4.20. The lines do not line up correctly.The lines should fan out from all corners. Individually, they look exactly like it should.
Example of one corner.
int width = getWidth(); int height = getHeight(); // upper-left corner int startX = 0; int startY = 0; int endX = 0;
[Code] ....
For the other corners I have different starting and ending positions.To draw upper-left corner I have a starting position of 0,0 and ending position of 0,height.I then move ending position up one vertical step and right one horizontal step. I repeat this fifteen times.
To draw upper-right corner I have a starting position of width,0 and ending position of width,height. I then move ending position up one vertical step and left one horizontal step.
To draw bottom-left corner I have a starting position of 0,height and ending position of 0,0. I then move ending position down one vertical step and right one horizontal step.
To draw bottom-right corner I have a starting position of width, height and ending position of width,0. I then move ending position down one vertical step and left one horizontal step.
For the second design Fig. 4.21 all my lines line up correctly no matter the direction I resize it. Both designs frame size is 250,250. Both designs are divided into fifteen steps.
I am trying to make GPA calculator. I decided to use only switch statement and make it as simple as possible. The point is to enter as many classes and students as user wants. I keep getting credit points 0 at the end and also text format is not good too. Here is the code.
import java.util.Scanner; import java.io.*; public class SwitchExercise{ public static void main(String[] args) { String grade = ""; String grades=""; String coursename=""; String headingleft="COURSES";
I am working on an assignment that is to simulate the relationship between a cache and main memory. Basically it is supposed to be a 16 slot cache and we are to have 500 for main memory. I need it to compare the corresponding index for both arrays, then go through then repeat the cache array and compare it to the next 16 of main memory. It is to simulate an direct mapped cache. How to compare two arrays from separate loops.
public class MainMemory { private short mainMem[] = new short[200]; public void assign(){ short i; for ( i = 0; i < mainMem.length; i ++){ mainMem[i] = i;