How To Use CTRL-D To Terminate Program (sentinel Value)
Mar 1, 2014
how to use the CTRL-D in my program. The program records the amount of times a positive and negative integer is typed. When the user decides to end the program, they will use the CTRL-D to terminate the program. After the button combination has been pressed, I spit out to the user the results. The problem is when I press CTRL-D the program just terminates and I can't even get it to read the next line of code. ....
I'm new to Java and am trying to create a simple payroll program that uses a while loop to repeat until the user enters "Stop" for the employee's name. I've tried everything I can think of and everything others have suggested and for some reason, I cannot get the program to differentiate between the word "Stop" or any other word. what I'm doing wrong? My code is as follows:
import java.util.Scanner; // imports scanner class for user input public class Payrolltest { public static void main( String[] args )// begins execution of program { Scanner input = new Scanner( System.in ); // creates a scanner to obtain user input String Employee = "name"; // employee's name
Write a java program that will ask a user to input grades until the user inputs the sentinel value -1. The program should test each input to determine whether 0<=grade<=100. If the grade entered is within this range, the program should print "Grade accepted;" if not, the program should print "Invalid input".
while (scan.hasNextInt()) { list.add(scan.nextInt()); }
It asks the user to input integers and passes them to an ArrayList of integers named list. Without any termination it works fine, but I am not sure about how to terminate the scanner at a specific value. I am trying to terminate the scanner once the user enters 0. Is there a method in the Scanner class that terminates at a specific value?
I've been trying while (scan.hasNextInt() && scan.nextInt() != 0 ) but it seems to only work on the second zero entered. For ex, if I enter 2 3 6 8 0 0 it stops on the second zero, not the first
I know how to do single selection, but I would like to do multiple row selection only by using CTRL + click without the option of dragging the mouse to select rows. So the user would have to hit ctrl + click each time to highlight additional rows.
(Count positive and negative numbers and compute the average of numbers). Write a program that reads an unspecified number of integers, determines how many positive and negative values have been read, and computes the total and average of the input values (not counting zeros). Your program ends with the input 0. Display the average as a floating-point number.
I moved the different boolean statements around, but I'm not getting the sentinel value to end the run. It continues to let me add integers endlessly. The code I wrote is below:
package exerciseFourOne; import java.util.Scanner; public class AverageOfIntergers { public static void main(String[] args) { // TODO Auto-generated method stub int positive = 0; // number of positive integers int negative = 0; // number of negative integers int sum = 0; // value of sum of integers
The program is supposed to print all even and odd numbers between 50 and 100 using ONE while or do while loop. The evens work, but the program terminates after printing 51 for the odds, which doesn't satisfy the second value sentinel value for the while loop.
public class EvenOdd { public static void main(String args[]) { int x = 50; int y = 50; int i = 0; int j = 0; System.out.print("Even numbers between 50 and 100: ");
Have written a program to open Excel sheet from java program.Below line works fine.
Process p = Runtime.getRuntime().exec(new String[]{""C:Program Files (x86)Microsoft OfficeOffice12Excel.EXE"","C:UsersRASHPA~ 1.ORAAppDataLocalTempExport_xl420314062726 9379706.xls"});
But below code gives error i.e. Executable name has embedded quote, split the arguments
In a project for school. I have a program that links several GUI's as a menu based program. What I am trying to accomplish is when one of the previous GUI's is closed that it doesn't terminate the entire program. There is a lot of classes in the entire project so I'd prefer not to paste all the code here, but if it is necessary I will do so.
I'm creating a program that will compile and run another java program:Lets say I have a program in directory
D:HelloWorldsrc and compiled program will be in D:HelloWorldin inside src and bin is a folder hello (that's a package)
package hello; public class HelloWorld { public static void main(String[] args) { System.out.println("Hello World"); System.out.println("Hello World"); } }
This program will be run by another program (that's the program that I am creating).Here is the code of my program:
package runnercompiler; import java.io.IOException; import java.io.InputStream; import java.util.logging.Level; import java.util.logging.Logger; public final class RunnerCompiler {
I'm working in a GUI program, but I'm not going to put the code because there is a lot of code and files. Instead, I will try to put it an example.
Let say:
I'm working in a GUI program that ask form the user to enter two number's. When the user press at the calculate button. It will show up the output. However, the program won't exit unless the user press at red (X).
int x = user_Input1; int y = user_Input2; int total = x + y; // JOptionPane.showMessageDialog(null, total);
I know that there will be a (total) now, so my question is here how can I reset all the calculation and have a new total that will show up when the user enter two number's again.
I have searched the internet for about 2 days and now i'm posting this. I'm trying to make a program that will let me enter "1" to show how many movies I have watched and press "2" for a new one. The problem I ran into is I enter 2 then when I enter 1 it said "you have watched 0 movies". I know what the problem is I just don't know how to retype it. here is the code.
package stuff; import java.util.*; public class thing {
I just finished a tutorial on youtube that covers the basic java, and now i want to try and make a game / program thing, only problem is that i have never worked with graphics before (i have tried to make ovals, rectangles, and other things with the paint method tho )
I know how to make a jframe and a jpanel, and i feel like i can make a simple "game" (not a complicated one, just a simple one with a guy walking around on the screen) in fact i have already make a such game, where you are a oval walking around on the screen, so thats not really my problem.
My problem is that i want to draw an image on the screen that can walk around instead of the oval, but how to do that. I have made a new project and set up the jframe and jpanel, and my code looks like this:
(main)
import javax.swing.JFrame; public class main_class { public static void main(String[] args){ JFrame f = new JFrame(); f.setTitle("title"); f.setVisible(true); f.setSize(800,600);
[code]...
but once again, i get a blank jframe with no image and no "test" string . How i can display images on the screen?
I am new on this and I will be working in a gpa and average program. This is my code so far: Every time that I try to add the gpa part it gives me errors or just duplicates whatever I've in average and displays it in gpa
/** * This program shows a database of students in a school. * It gathers information as name, classes, grades, and calculates average and gpa average. * */ import javax.swing.JOptionPane;
In this exercise you will write a program that estimates the value of π. Pretend that we are looking at a dartboard in the picture above. If the square is 2units wide and 2 units high, the radius of the circle within the square is 1 unit. Then the area of the circle is π*r2 = π*12 = π. The area of the square will be 2*2 = 4.
The estimation of π will work by randomly "throwing darts" at the dartboard. We will assume that every dart will hit the board but the location of that strike will be random so some darts will land inside the circle and some will land outside the circle. The calculation of π is then the ratio of the number of darts that land inside the circle to the total number of darts, multiplied by 4. Note that as we increase the number of darts used in the simulation, the accuracy improves.
Follow the steps to complete the program:
1.Declare variables that represent x, y coordinates of a dart, the distance of the dart from the origin, the number of darts that land inside the circle, and the total number of darts.
2.Read in the total number of darts (N) from the user and create an instance of the Random class.
3.Create a loop that runs N times. Inside the loop, you will use the nextFloat() method of the Random class to create x, y coordinates randomly, and then compute the distance of the dart from the origin. Determine whether the dart lands inside or outside of the circle.
4.Compute π using the estimation algorithm.
5.Run the program with increasing numbers from 100 to 100,000,000 and observe the accuracy of π.
A file has the data of the subjects and name of professors. The file contains line for each subject. The line starts with professor Name followed by the Subject name.
Harry Williams Advanced DBMS
James H Computer Networks
Sasha Ben Artificial Intelligence
Harry Williams Software Engineering
Palbo Kastro Formal Languages
Alex W Advanced SE
James H Operating System
Harry Williams Theoretical Foundation
Write a program with setter getter method to read the file, and then write a class to store several professors in a hashset (Single Key and Multiple Values).The program should be able to display all the professors in the set and allow the user to search for a professor.
Input:
Professor Name: James H. Then the Output will be:
Subjects Taken by the professor: Computer Networks, Operating System.Display No Classes available if the professor name does not exists .
The objective of the program: Write a method that takes a string as input and returns the letters contained in that string in sorted order as output. For example, an input of "Computer Science" would print the following as output (case is ignored): ccceeeimnoprstuthe code works otherwise
import java.util.Scanner; public class weeklyProblem4 { public static void main(String[] args) { Scanner console = new Scanner (System.in); System.out.println("This program takes a string as input and returns the letters contained in that string in sorted order as output"); System.out.println(); System.out.println("Enter some string"); String userstring = console.nextLine(); sortedString(userstring);