Looking for some simple descriptive pseudocode for this short Java program (example italicized in bold directly below):
//Create public class count
public class Count
{
public static void main(String args[])
{
int n = getInt("Please
enter an integer value greater than or equal to 0");
System.out.println("Should count down to 1");
countDown(n);
System.out.println();
System.out.println("Should count up from 1");
countUp(n);
}
private static void countUp(int n)
{
// IMPLEMENT THIS RECURSIVE METHOD
if(n==0)
return;
countUp(n-1);
System.out.println(n);
// END IMPLEMENTED RECURSIVE VALUE
}
private static void countDown(int n)
{
// IMPLEMENT THIS RECURSIVE METHOD
if(n==0)
return;
System.out.println(n);
countDown(n-1);
// END IMPLEMENTED RECURSIVE VALUE
}
private static int getInt(String
rangePrompt)
{
Scanner input;
int result =
10; //default value is
10
try
{
input = new Scanner(System.in);
System.out.println(rangePrompt);
result = input.nextInt();
}
catch(NumberFormatException e)
{
System.out.println("Could not convert input to an integer");
System.out.println(e.getMessage());
System.out.println("Will use 10 as the default value");
}
catch(Exception e)
{
System.out.println("There was an error with System.in");
System.out.println(e.getMessage());
System.out.println("Will use 10 as the default value");
}
return result;
}
}
CODE IN JAVA:
Count.java file:
import java.util.Scanner;
public class Count
{
public static void main(String args[])
{
int n = getInt("Please enter an integer value greater than or equal
to 0");
System.out.println("Should count down to 1");
countDown(n);
System.out.println();
System.out.println("Should count up from 1");
countUp(n);
}
//descriptive method for countUp
private static void countUp(int n)
{
for(int i=1;i<=n;i++) {
System.out.println(i);
}
}
//descriptive method for countDown
private static void countDown(int n)
{
for(int i=n;i>=1;i--) {
System.out.println(i);
}
}
private static int getInt(String rangePrompt)
{
Scanner input;
int result = 10; //default value is 10
try
{
input = new Scanner(System.in);
System.out.println(rangePrompt);
result = input.nextInt();
}
catch(NumberFormatException e)
{
System.out.println("Could not convert input to an integer");
System.out.println(e.getMessage());
System.out.println("Will use 10 as the default value");
}
catch(Exception e)
{
System.out.println("There was an error with System.in");
System.out.println(e.getMessage());
System.out.println("Will use 10 as the default value");
}
return result;
}
}
OUTPUT:
![Problems Javadoc Declaration Console Coverage <terminated> Count Java Application] C:\Program FilesJavajre1.8.0 171\bin\javaw](http://img.homeworklib.com/questions/45e1ddc0-8217-11eb-89bd-a586c7c7cd0d.png?x-oss-process=image/resize,w_560)
Looking for some simple descriptive pseudocode for this short Java program (example italicized in bold directly...
In java need help with the TODO sections creating recursive methods public class CountUpDown { /** * countUp - a recursive function that counts up from 1 to n * * @param n the integer value to count up to */ private static void countUp(int n) { // TODO PRELAB // IMPLEMENT THIS RECURSIVE METHOD } /** * countDown - a recursive function that counts down from n to 1 * * @param n the integer value to count down...
Exercise 1): take the program “InteractiveCounting” (attached). Your task is to change the implementation of both the “ReadInput” and the “Count” classes. Currently these classes extends Thread. You should now use the Runnable interface to implement the thread. The output of the program should not change. I have also attached the class ThreadType2 to give you a working example on how to implement a thread using the Runnable interfacethe program is here package threadExamples; import java.util.Scanner; public class InteractiveCounting {...
My Question is: I have to modify this program, even a small modification is fine. Can anyone give any suggestion and solution? Thanks in Advanced. import java.util.*; class arrayQueue { protected int Queue[]; protected int front, rear, size, len; public arrayQueue(int n) { size = n; len = 0; Queue = new int[size]; front = -1; rear = -1; } public boolean isEmpty() { return front == -1; } public boolean isFull() { return front == 0 && rear ==size...
Hi. This is a prototype of Java. The following Java program was developed for prototyping a mini calculator. Run the program and provide your feedback as the user/project sponsor. (Save the code as MiniCalculator.java; compile the file: javac MiniCalculator.java; and then run the program: java MiniCalculator). HINTs: May give feedback to the data type and operations handled by the program, the way the program to get numbers and operators, the way the calculation results are output, the termination of the...
Help check why the exception exist do some change but be sure to use the printwriter and scanner and make the code more readability Input.txt format like this: Joe sam, thd, 9, 4, 20 import java.io.File; import java.io.PrintWriter; import java.io.IOException; import java.io.FileNotFoundException; import java.io.FileWriter; import java.util.Scanner; public class Main1 { private static final Scanner scan = new Scanner(System.in); private static String[] player = new String[622]; private static String DATA = " "; private static int COUNTS = 0; public static...
JAVA: Rewrite the following code to where the inputs are from a file. The file name will be from the input from the user scanner. CODE: import java.util.*; public class Q1 { public static int sumOD (int k) { int sumOD = 0; int in = k; while (in != 0) { int digitON = in % 10; sumOD += digitON; in /= 10; } return sumOD; } public static void main(String[] args) { int n, i, k; System.out.println("Enter...
Modify the program that you wrote for the last exercise in a file named Baseball9.java that uses the Player class stored within an array. The program should read data from the file baseball.txt for input. The Player class should once again be stored in a file named Player.java, however Baseball9.java is the only file that you need to modify for this assignment. Once all of the input data from the file is stored in the array, code and invoke a...
in java coorect this code & screenshoot your output ---------------------------------------------------------------------- public class UNOGame { /** * @param args the command line arguments */ public static void main(String[] args) { Scanner input=new Scanner(System.in); Scanner input2=new Scanner(System.in); UNOCard c=new UNOCard (); UNOCard D=new UNOCard (); Queue Q=new Queue(); listplayer ll=new listplayer(); System.out.println("Enter Players Name :\n Click STOP To Start Game.."); String Name = input.nextLine();...
Hello, can get some help with simple pseudocode describing the steps for this program below? THUMBS UP always left for help! public class TimeDemo { private static Scanner keyboard; private static String enteredTime; private static Time now; public static void main (String [] args) { keyboard = new Scanner(System.in); char answer = 'Y'; enteredTime = null; String response; while (answer== 'Y') { System.out.print( "Enter a military time using the ##:##...
java create java program that make stack with LinkedList and stack is implement iterator. When stack’s iterator call next(), it pop its data. here is the example of output //by user 5 1 2 3 4 5 //then output comes like this 5 4 3 2 1 Stack is empty. here is the code that i'm going to use class Stack<T> implements Iterator<T> { LinkedList<T> list; public Stack() { list = new LinkedList<T>(); } public boolean isEmpty() { return list.isEmpty(); ...