Program Prints 2 Values Instead Of One
Feb 4, 2015
When I run this code, it is supposed to get one value from turnTimer(); and return it, just as a test. This works when I enter a valid pit. For example. If I were to input "A" when it's player one's turn, it will return 1, like it should. However, if I were to type "H" when it's player one's turn, it returns "Not a valid pit!"(like it should) but then it also returns 12. It shouldn't know that H is 12 because it's in a separate method. I'm confused as to why it's printing both values.
import java.util.*;
public class Mancala {
static Scanner input = new Scanner(System.in);
public static int pit;
public static void main(String[]args) {
Mancala mancala = new Mancala();
int[] board = {0,3,3,3,3,3,3,0,3,3,3,3,3,3};
[Code] .....
View Replies
ADVERTISEMENT
Feb 4, 2015
When I run this code, it is supposed to get one value from turnTimer(); and return it, just as a test. This works when I enter a valid pit. For example. If I were to input "A" when it's player one's turn, it will return 1, like it should. However, if I were to type "H" when it's player one's turn, it returns "Not a valid pit!"(like it should) but then it also returns 12. It shouldn't know that H is 12 because it's in a separate method. I'm confused as to why it's printing both values.
import java.util.*;
public class Mancala
{
static Scanner input = new Scanner(System.in);
public static int pit;
public static void main(String[]args)
{
Mancala mancala = new Mancala();
int[] board = {0,3,3,3,3,3,3,0,3,3,3,3,3,3};
[code]....
View Replies
View Related
Feb 8, 2014
I was told to create a program that prints the time between 00:00 (0:00 a.m.) and 23:45 (11:45 p.m.) in the 24-hour clock and 12-hour clock format like this:
24-hour Clock 12-hour Clock
-----------------------------
00:00 0:00 a.m.
00:15 0:15 a.m.
00:30 0:30 a.m.
00:45 0:45 a.m.
01:00 1:00 a.m.
01:15 1:15 a.m.
01:30 1:30 a.m.
01:45 1:45 a.m.
02:00 2:00 a.m.
ect...
but cant seem to create the program and my program doesnt seem to run.
View Replies
View Related
Apr 8, 2015
So I'm trying to write a program that prints out the "most-repeated integer" in an Array.
For example: if an array contains {1,2,2,3} It would print out 2 as the result.This is what I got so far and according to my knowledge I think I'm correct but for some reason it doesn't work.. Please give me some inputs.
public class MostInt{
public MostInt (){
int[] array = {0};
for(int i = 0;i>array.length;i++){
if(i==i++){
System.out.println(i);
[Code]...
View Replies
View Related
Dec 30, 2014
Write a java program that prints 0..........121..........23432..........3456543............456787654............56789098765 in this pattern?
My code:
public class Number {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
int k=0;
for(int n=0; n<=10; n=n+2)
[code]....
View Replies
View Related
May 9, 2015
Here is my code :
import java.util.Scanner;
public class smallestnumber
{
public static void main(String args[])
{
Scanner input=new Scanner(System.in);
int smallest =0;
int number;
[Code]...
here is the output of my code:
Enter the number
88
Enter the number
8
Enter the number
6
Enter the number
55
[Code]...
Why is it printing 0 instead of 1?
View Replies
View Related
May 10, 2015
I am trying to write a java program that prints out the number that is the mathematical constant e. As you input a number, the larger it gets , the closer it comes to 2.71828 . Here is my code:
//taylor series that prints out e^1=1+1/1!+1/2!+1/3!+.....
import java.util.Scanner;
public class taylor_1
{
public static void main(String args[]) {
Scanner input=new Scanner(System.in);
int factorial =1;
[Code] .....
Here is the output of my code:
enter n
9
Taylor series is 9.0
View Replies
View Related
Jan 9, 2015
Write a program (TwoIntegers.java) that prompts the user to enter two positive integers and prints their sum (by addition), product (by multiplication), difference (by subtraction), quotient (by division), and remainder (by modulation). When the user enters 5 and 3, the output from your program should look exactly like the following:
Enter two positive integers: 5 3
The sum is 8.
The product is 15.
The difference is 2.
The quotient is 1.
The remainder is 2.
import java.util.Scanner;
public class TwoIntegers {
public static void main(String[] args) {
System.out.println("Enter two positive integers: ");
Scanner userInput = new Scanner("System.in");
int integer1 = userInput.nextInt();
int integer2 = userInput.nextInt();
[code]....
View Replies
View Related
Nov 18, 2014
Write a program that asks the user for an integer andthen prints out all its factors in increasing order. Use a class FactorGenerator with a constructor FactorGenerator(int numberToFactor) and methods nextFactor and hasMoreFactors. Supply a class FactorTester whose main methods reads a user input, constructs a FactorGenerator object and prints the factors.
Here is what I have so far for my main class and tester class
public class FactorGenerator
{
int factor;
int number;
int x;
FactorGenerator(int numberToFactor)
{
number = numberToFactor;
}
[Code]....
View Replies
View Related
Mar 9, 2014
I am to design a program in java that will allow a user to Input a list of your family members along with their age and state where they reside. Determine and print the average age of your family and print the names of anyone who live in Texas. I have tried but my results are wrong.
View Replies
View Related
Oct 18, 2014
Program to pull prime numbers between two entered values,
import java.util.Scanner;
public class question6 {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.println("Enter lower int:");
[Code] ....
View Replies
View Related
Aug 26, 2014
I was trying to write a program that will accept values and transform the scores to grade. Like 70 and above will be given A from 60 to 69 is B, from 50 to 59 is C, from 40 to 49 is D and below 40 is F. I have defined the variables, for the textfield, am confused on how make this hapen on just a click of the comand botton.
View Replies
View Related
Jan 13, 2014
I am trying to test values stored in 2d arrays once but i my program just keeps looping what am i doing wrong
Java Code:
tempi=i;
tempx=x;
for( i=0;i<3;i++) {
for( x=0;x<4;x++) {
if(rounded[i][x]<395 || rounded[i][x] >405) {
System.out.println("there is an error with probes "+rounded[i][x]);
[Code] .....
View Replies
View Related
Apr 1, 2014
I'm making a program for school that reads a text file with answers to a personality test and prints the temperament to an output file. Problem is, it sets the temperament for the first person to INFJ and then prints INFJ for the rest of the people too. My code is below, and the input file 'personality.txt' goes like this:
Betty Boop
BABAAAABAAAAAAABAAAABBAAAAAABAAAABABAABAAABABABAABAAAAAABAAAAAABAAAAAA
Snoopy
AABBAABBBBBABABAAAAABABBAABBAAAABBBAAABAABAABABAAAABAABBBBAAABBAABABBB
Bugs Bunny
[Code] ....
This is my Code :
public static void main(String[] args) throws FileNotFoundException {
welcome();
Scanner input = new Scanner(new File("personality.txt"));
PrintStream out = new PrintStream(new File("output.txt"));
int[][] outcome = new int[4][2];
double[] percent = new double[4];
[Code] .....
View Replies
View Related
Feb 21, 2015
I have to meet certain requirements for this one program, and one of them is as follow: The program will require the user to enter the needed values one after another. If any of the entered values is invalid, then the program will detect that and go into a loop requiring the user to enter a valid value. The program must keep track of the total number of invalid values that the user has entered.
I know how to set a restriction and create a loop to keep asking the same question until it is satisfactory ( in this case I used a while loop) but I am at loss on how I should keep track of the total number of invalid values. I know I can use an increment but how do I set a variable for when the program meets an wrong input from the user.
View Replies
View Related
Mar 24, 2014
How to get used to program control statements. This is an attempt to write a program that returns the number of days between two dates. Sadly, it give incorrect values.
public class DaysBetweenDates {
public static boolean isLeapyear(int year) {//This method will determine if a year is a leap year or not
boolean isTrue=false;
if(year%4==0 && year%100!=0) isTrue=true;
else if(year%400==0) isTrue=true;
return isTrue;
[Code] ....
View Replies
View Related
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
Jan 20, 2015
The second message dialog result is always 0 ... i want to find the minimum grade...
import javax.swing.*;
import java.util.Arrays;
public class Parrarrapapa{
public static void main (String[]args){
String length = JOptionPane.showInputDialog("Number of students");
[code]....
View Replies
View Related
Nov 16, 2014
Ok, so let's say I am having a user input scores and at the end I want to print out the results so I do something like:
int[] Scores = new int[1000];
//code to ask user for input and store into array //
The user only inputs lets say 5 scores out of possible 1000. I then try to print it out by doing something like this:
for(int counter = 0; counter < Scores.length; ++counter) {
System.out.println(Scores[counter])
}
How would I go about printing out only the index's that were input, because right now it prints out the scores and then 995 0's after.
View Replies
View Related
Dec 6, 2014
I'm tyring to print the same output in console to a text file, but I can only get the last line of the console output in the text file, not sure what is wrong with my code:
while (in.hasNextLine()) {
PrintWriter writer = new PrintWriter("output5.txt");
tempS = in.nextLine().toLowerCase();
System.out.println(wp.bestPages(tempS));
[code]....
What's causing only the last time to be printed in text file? Are there better ways to print console outputs into a text file than PrintWriter?
View Replies
View Related
Dec 8, 2014
I've a ArrayList with dogs on, and I've a function that should allow me to delete a dog from the register and if the dog was found it prints "The dog was deleted" and if the dog doesn't exist in the arraylist it should print "the dog couldn't be found".
Everything works perfect until I shall delete a dog that is not first on the list. Then the program shows first "dog was not found" and on the row after "the dog was deleted" if the dog was second on the list. If it was third I will get 2 messages that the dog wasn't found and then that the dog was deleted. I've no clue why it prints both else and if!
public static void taBortHund(){
//Har tar vi bort hund fran listan
//System.out.println(hundlista);
System.out.print("Vilken hund vill du ta bort? ");
String hunden = tangentbord.nextLine();
for (int taBort = 0; taBort<hundlista.size(); taBort++){
[code]....
View Replies
View Related
Sep 30, 2014
I am stuck and having a problem trying to find what i believe is a simple fix but can't wrap my head around it. For class I needed to make a table that prints out Sin,Cos,Tan for angles in steps of 5 to 180. The problem is in my output with the first couple lines of the table. for angle 5.0 the Sin(.0872) Cos(.9962) and Tan (.0875) are being displayed on the angle line 10.0
public class TrigTable {
public static void main(String[] args) {
double angle = 0;
double sin =0;
double cos = 0;
double tan = 0;
System.out.println("Angle Sin Cos Tan"); // Table header for the values
[Code] ....
Here is the first couple lines of output:
Angle Sin Cos Tan
----- --- --- ---
0.0 0.0 1.0 0.0
5.0 0.0 1.0 0.0
10.0 0.0872 0.9962 0.0875
15.0 0.1736 0.9848 0.1763
20.0 0.2588 0.9659 0.2679
View Replies
View Related
Feb 5, 2015
I need to add Logger function in the catch block that prints time, date and description of the what had happened.
public class InputUtil {
public static final String[] SPECIAL_CHARACTERS = { "!", "#","%", "^", "=",
"+", ";", "[", "]", "|", "<", ">", "?", "~", "`", "-", "" };
public static String deleteSpecialCharacters(String inputString) {
String outputString = inputString;
[Code] ....
View Replies
View Related
May 7, 2014
Write a method that prints characters using the following: public static void printChars(char ch1, char ch2, int numberPerLine). This method prints the characters between ch1 and ch2 with specific numbers per line. Characters are separated by exactly one space.Test your method with the following main method:
public static void main(String[] args)
{
printChars(‘A’,’z’,10);
printChars(‘0’,’9’,5);
}
View Replies
View Related
May 25, 2014
I made a heads or tails game but I'm getting a bug when the user says he doesn't want to play anymore. The statistics are printed as many times as the games played. If you want to test the code, write" cap" " pajura" and when the program says "Vrei sa mai joci?" that means "do you wanna play another one?" and you can answer with "da"(yes) or "nu"(nu) Here is the code:
import java.util.Scanner;
public class cap_sau_pajura{
private static int user;
private static int pc;
private static String converted;
static int usermove;
private static int castiguri = 0;
private static int pierderi = 0;
[code]....
View Replies
View Related
Dec 6, 2014
Let's say if I want to create a dot file that print this graph in Java, how do i go about it?
I'm starting with this:
PrintWriter writer = new PrintWriter("graph.dot");
View Replies
View Related