How To Just Read User Input

Sep 29, 2014

i need to output the unsorted array as well as the sorted array...the sorted array works but i can not get the unsorted array to work.

package Lab7;
import java.util.Scanner;
public class lab10 {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner keyboard = new Scanner(System.in);

[Code]...

View Replies


ADVERTISEMENT

Read From User Input (integer) And Reduce It By Multiplying Its Non-zero Digits

Nov 15, 2014

Write a program that reads from the user an integer and reduce it by multiplying its non-zero digits. The result of the multiplication is a number which is to be reduced as the initial one. This process continues until an integer of one single digit is obtained. For example:

64734502 (6 * 4 * 7 * 3 * 4 * 5 * 2) 20160 (2 * 1 * 6) 12 (1 * 2) 2

Your program should display the number obtained in every iteration.

Sample run1
Enter an integer: 64734502
After iteration 1: 20160
After iteration 2: 12
After iteration 3: 2

Sample run2
Enter an integer: 97737999
After iteration 1: 6751269
After iteration 2: 22680
After iteration 3: 192
After iteration 4: 18
After iteration 5: 8

View Replies View Related

Writing A While Loop To Read Positive Integers From User Until User Enters EOF Character

Feb 24, 2014

import java.util.Scanner;
public class Project_5
{
public static void main (String[] args)
{
Scanner input= new Scanner (System.in);

[code]....

So I'm attempting to have this program take the users input of integers, pressing enter in between each one. If they enter a negative number it lets them know that its invalid. At the end of the program it takes all of the valid integers entered and must add them and average them. I've put the final println in there as a placeholder. If the user types in "6" then presses enter and types in "3" , the output is:

There were 3 valid numbers entered.
The sum of the valid numbers was --- and the average was ---.
There were 0 invalid numbers entered.

It then continues on allowing the user to enter more values. Here is the example output for correct code"

Enter a positive value (EOF to quit): 4
Enter a positive value (EOF to quit): 7
Enter a positive value (EOF to quit): 8
Enter a positive value (EOF to quit): 2
Enter a positive value (EOF to quit): -1
The number "-1" is invalid.

Enter a positive value (EOF to quit): 8
Enter a positive value (EOF to quit): 0
Enter a positive value (EOF to quit): -4
The number "-4" is invalid.

Enter a positive value (EOF to quit): CTRL-D

There were 6 valid numbers entered.
The sum of the valid numbers was 29 and the average was 4.83.
There were 2 invalid numbers.

View Replies View Related

Java Program That Will Ask A User To Input Grades Until User Inputs Sentinel Value

Apr 9, 2014

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".

View Replies View Related

Program That Takes User Odd Number And Print Prime Numbers Lower Than User Input

Nov 4, 2014

I have been struggling with this program for weeks. This program is supposed to take a user's inputted odd number and then print out all prime numbers lower than that number.

public class PrimeNumber
{
Scanner scan = new Scanner(System.in);
int userNum;
String neg;

public void getUserNum()

[code]...

View Replies View Related

Where To Input Segment To Get User Input Dialog

Apr 9, 2015

Where do I input this segment?

Scanner user_input = new Scanner( System.in );// This line goes at the top with the other global variables

public void getUserInput(){
System.out.print("Enter litres: ");
litres = user_input.nextDouble( );
System.out.print("Enter mileage: ");
mileage = user_input.nextDouble( );
System.out.print("Enter speed: ");
speed = user_input.nextDouble( );

[Code] ....

This is my client file.

class Client{
public static void main(String []args){
Bike R1=new Bike(5.0, 60.0,30.0);//create bike object with params
Bike R2=new Bike();//without params
System.out.println(R1.increaseSpeed());//calling methods
System.out.println(R1.maxDistance());
System.out.println(R2.increaseSpeed());
System.out.println(R2.maxDistance());
}
}

View Replies View Related

Read From File Input

Oct 25, 2014

The program is reading from file input. how can I replace hate with love the file contains only one line.I hate programing!

Java Code:

[import java.util.Scanner;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
public class Program3 {
public static void main(String[] args) {
Scanner fileIn = null;

[code]...

View Replies View Related

How To Read Input Of Source Code With FileReader

Oct 19, 2014

I'm doing homework and as far as input, my assignment reads: "Your program must take as input the name of a Java source code file such as the source file containing the source code of this assignment." So my question is, how do i do that without linking the directory directly (i.e. C:/users/...)? I'm using FileReader as shown below...

public static void main(String[] args) throws Exception {
FileReader file = new FileReader (WHAT GOES HERE???);
BufferedReader reader = new BufferedReader(file);
String s = "";
String line = reader.readLine();
 
[Code] .....

View Replies View Related

Failing To Read Input With Scanner NextLine

Jan 29, 2014

I Just made a simple code, but in any case it's not taking the input I'm trying to enter for the city.

View Replies View Related

Why Won't Read Input File (WordPad Document)

Sep 12, 2014

I keep receiving an error in which State.Fall.txt can not be read. I can't point it directly to a drive because someone else needs to open it. I saved it in wordpad as a text file. My question is what did I do wrong in my code that it can't directly access the wordpad document? 
 
import java.io.*;
public class Main {
/**
* @param args the command line arguments
*
*/
public static void main(String[] args) throws IOException
{
// Create an array of individual state objects to hold 50 items

[Code] ....

View Replies View Related

Make Library That Will Read Some Input Files From A File?

Apr 23, 2015

I am trying to make a Library that will read some Input Files from a File . Like When We Enter Nuber from a System.in

1
2
45
667

77
34

and then store these values in int[] array

What I want is I Save all these values in a File and at Run time pass path of that file to command line arguments and then int[] array will be initialize using that

something like this [URL]

View Replies View Related

Second Packet Read From Input Stream Has Incomplete Data

May 8, 2015

I a simple server that receives bytes using TCP and then saves them to a file stream.Through many tests I have seen that the first packet received is always just the filename with no other data. The second packet received only has one byte and it is the first letter of the input text file. After this all packets are sent correctly, but I can't seem to figure out what is messing up the second packet. It also appears that the last packet is written twice.

Here is an example Input/Output: [URL] .....

InputStream in = clntSock.getInputStream(); //server's input stream - gets data from the client
OutputStream out = clntSock.getOutputStream(); //server's output stream - server sends data to the client
byte[] byteBuffer = new byte[BUFSIZE];
int count = in.read(byteBuffer, 0, BUFSIZE);
String firstRead = new String(byteBuffer, 0, count);

[Code] ....

Another peculiarity to me is that the second to last packet is always just "-" and then the last packet has the remainder of the magic string which terminates the file output stream.

I am aware that it is not safe to make the assumption that the file name will be sent in one go before the loop, but I wil fix that later. I am not concerned about it at all now. THe problem si that the loop should account for any amount read in, but for some reason the first packet always contains one letter, and the second packet picks up around 16000 bytes later for some reason. Why would this be?I can't edit my above post so here is the code with code tags.

InputStream in = clntSock.getInputStream(); //server's input stream - gets data from the client
OutputStream out = clntSock.getOutputStream(); //server's output stream - server sends data to the client
byte[] byteBuffer = new byte[BUFSIZE];
int count = in.read(byteBuffer, 0, BUFSIZE);
String firstRead = new String(byteBuffer, 0, count);

[Code] ....

View Replies View Related

Read Line Of Input For A File - String Tokenizer

Jan 27, 2015

So I'm having a problem with the .hasMoreElement() method. I try to read lineOfInput for a file which contains:

Hobbit, Long,t@gmail.com,475-555-4444,3
Long, Hobbit,b@yahoo.com,445-222-5342,2
Hobbit,Long,b@yahoo.com,465-222-5342,2
Help,Yerp,,455-222-2222,4

but when i get to the ,, on the last line I get a NoSuchElementException and the program crashes.

StringTokenizer inputField = new StringTokenizer(lineOfInput, ",");
while(inputField.hasMoreElements()) //for each fields is a line
{
lastName = inputField.nextElement().toString();
firstName = inputField.nextElement().toString();
email = inputField.nextElement().toString();
phoneNumber = inputField.nextElement().toString();
level = Integer.parseInt(inputField.nextElement().toString());
}

View Replies View Related

Unable To Read Input File When Adding Pictures To A JFrame

Aug 25, 2014

i've tried changing the path 10000 times. idk if its wrong in the code.

Java Code: import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

[Code]...

View Replies View Related

Program That Read Sequence Of Input Values And Display Bar Chart

Oct 21, 2014

Write a program that reads a sequence of input values and displays a bar chart of the values, using asterisks, like this:

********************** **************************************** **************************** ************************** **************

You may assume that all values are positive. First figure out the maximum value. That value's bar should be drawn with 40 asterisks. Shorter bars should use proportionally fewer asterisks.

import java.util.Scanner;
import java.util.ArrayList;
import java.util.Arrays;
public class Array717
{
public static void main( String[] args )

[Code] ....

The problem is that all this code does is print 1 line of *'s and what seems to be thousands of them

View Replies View Related

Program To Read Input Of Morse Code And Then Produce Output Of English

Aug 25, 2014

I'm having some trouble with getting this program to read an input of morse code and then produce an output of English. When typing in morse code for the phrase 'the string', the output looks something like this:

- .... .
t
h
... - .-. .. -. --.
s
t
r
i
n

The English-->Morse works just fine.

import java.util.Scanner;
public class project1
{
static final String[] alpha = {
"a", "b", "c", "d", "e", "f", "g", "h", "i",
"j", "k", "l", "m", "n", "o", "p", "q", "r",
"s", "t", "u", "v", "w", "x", "y", "z", " "

[Code] .....

View Replies View Related

JSF :: How To Read CSV File From User Defined Directory Path For Loading To Managed Bean

Jan 10, 2015

I'm using a PrimeFaces UploadedFile xhtml page to select a csv file to read and write using a managed bean (SuperCSVParser.java). The file is read and written to an entity class which then persists the data to a database. The application works fine if I specify a file path on the physical server and select a csv file on that file path. But for the production version I want the user to select ANY file name from ANY directory on their local system.

I know about the FacesContext methods and I've looked at some methods from the java.io File class. Most of these methods are about getting the path from the server, where I want to 'pass' the path String from the client machine to allow the uploaded file to go through. When I try with the below code I get:

java.io.FileNotFoundException: data.csv (The system cannot find the file specified)

I'd like to know what I'm doing as I prefer not to explicitly declare a path in the final app. I'm almost sure that's possible.

<h:form enctype="multipart/form-data">
<p:fileUpload value="#{SuperCsvParser.file}"
mode="simple"
auto="true"

[Code].....

View Replies View Related

How To Get User Input

Nov 13, 2014

I have been coding in my class at school (Grade 11 Computer science) and i just downloaded the program on my computer at home, unfortunately i cannot access my computer notes at home and i also dont remember certian specifics of coding, so my question is how would i get user input to create a program. The comments are the parts i dont remember. (I am trying to slowly build my memory with this stuff)

Here is my code so far:

import java.util;
[highlight=java]
public class hello_world {
public static void main(String[] args) {
string name;
//WHAT DO I PUT HERE????

[code]....

View Replies View Related

Asking User For Input Twice?

Apr 19, 2014

I'm working on creating a dice game and getting the users input is giving me a really hard time. I have the main game working but this part I'm stuck on. The problem is that it's not giving me the chance to enter the second input when I ask for the game.

//Create Scanner object
Scanner keys = new Scanner(System.in);
//Get chips

[Code]....

*****This is what I get when I run it

run:

How much money would you like to change? 50

You now have $50 in chips.

What game do you want to play? You did not pick dice.

View Replies View Related

Can Control User Input

Oct 11, 2014

Is there a way you can control user input?

For example, is it possible to only allow the user to enter digits?

View Replies View Related

Formatting User Input

Feb 4, 2014

I have been given a piece of work to do for College that requires me to format user input. For example: This is an example of text that will have straight left and right margins after formatting

will transform into:

This..is..an.example
of..text..that..will
have..straight..left
and...right..margins
after.....formatting

The user inputs the width, in the case above being 20. Each line has to therefore be 20 characters long. All spaces are to be replaced with full stops.

This.is.an.example.o
f.text.that.will.hav
e.straight.left.and.
right.margins.after.
formatting..........
public class Main {
public static void main ( String args[])

[code]....

View Replies View Related

ArrayList - Get User Input And Sum Together

Jul 2, 2014

Goal is to get user input and sum together. I've tried it different ways. This is the one with the least amount of problems.

Exception in thread "main" java.lang.RuntimeException: Uncompilable source code - Erroneous sym type: java.lang.Integer.parseInt

ArrayList<Integer> leftCU = new ArrayList<>(); {
System.out.println
("Please enter one at a time the number of CU's for each class that is left to complete. Enter Q when done.");
leftCU.add(in.nextInt());

[Code] .....

View Replies View Related

Get User Input For A Char Value?

Jan 9, 2015

I am trying to get user input for a char value and am having some difficulty getting input for a char value.

Java Code:

//imports packages
import java.io.*;
import java.text.DecimalFormat;
class ModuleCulminatingTask {
public static void main (String args []) {
//declares variables
float var3, var4;
long var5 = (int)(Math.random()*10);

[code]....

View Replies View Related

Simple Input Value From User

Apr 10, 2014

I'm not sure what is wrong with my code:

import java.util.Scanner;
public class Main {
int age = 0;
System.out.println("Enter your age: ");
// Read in values
age = in.nextInt();
}

The in is underlined, telling me "cannot find symbol"

View Replies View Related

Getting User Input Second Time

Apr 19, 2014

I'm working on creating a dice game and getting the users input is giving me a really hard time. I have the main game working but this part I'm stuck on. The problem is that it's not giving me the chance to enter the second input when I ask for the game.

//Create Scanner object
Scanner keys = new Scanner(System.in);
//Get chips
System.out.print("How much money would you like to change? ");
int chips = keys.nextInt();
System.out.println("You now have $" + chips + " in chips.");

[code]...

This is what I get when I run it run/How much money would you like to change?

View Replies View Related

2D Array Input User For GUI

Mar 25, 2014

Java Code:

import javax.swing.*;
import javax.swing.table.*;
import java.awt.*;
public class SortTable {
public static void main(String args[]) {
Runnable runner = new Runnable() {
public void run() {

[Code]...

View Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved