DO NOT USE ANY EXTERNAL LIBRARIES BESIDES BUILT IN JAVA LIBRARIES! KEEP IT SIMPLE!!!
Provided Code:
import java.util.Scanner;
public class OddAndEven{
/* PART 1: Create a nonstatic method that takes in an int number
quantity (n) and returns a returns a
String of numbers from 0 to n (inclusive) as the example above
demonstrates. Call this quantityToString.
In this method you should check that n is between 0(inclusive) and
100(inclusive).
If n is outside these boundaries return and empty String
("").
*/
//*****Student Code Here*****//
/* PART 2: Next, you will implement oddAndEvenNumbers method that
generates two string's (odd and even) and
then prints the results at the end.
-A String which holds Odd Numbers
-A String which holds Even Numbers
Use if statements to check whether numInfo is less than 11, is
numInfo is less than 11 then it only contains single digit
numbers.
else: if numInfo is greater than 11 then it has both single digits
and double digits.
Single and double digit nummbers must be checked for
different.
single digit numbers: can be checked at an index since single digit
numbers are only 1 digit long.
double digit numbers: have to be checked as a double digit numbers,
therefore, when fetching a double digit number at an index, you
have to fetch the preceeding index as well because it is 2 digits
long and 2 indexes long. (Substring())
Use two loops, one loop will be for single digit numbers (0
-9)
and the other will be for double digit numbers. (10 - 99)
*/
public void oddAndEvenNumbers(int num) {//Start of method
//Variables
String numInfo = ""; //reassign to the String that quantityToString
returns
String odd = "";
String even = "";
//*****Student Code Here*****//
//Prints the results *Do not need to change this part*
System.out.println("Odd Numbers: " + odd);
System.out.println("Even Numbers: " + even);
}//End of method
public static void main(String[] args) {
//Testing -- Uncommented when done//
/*
OddAndEven obj = new OddAndEven();
System.out.println("Testing n = 5");
obj.oddAndEvenNumbers(5);
System.out.println("Testing n = 10");
obj.oddAndEvenNumbers(10);
System.out.println("Testing n = 15");
obj.oddAndEvenNumbers(15);
System.out.println("Testing n = 99");
obj.oddAndEvenNumbers(99);
*/
}
}
Code:
import java.util.Scanner;
class OddAndEven{
String quantifyToString(int n){
if(n<0 || n>100){
return "";
}
else{
String
s="";
int i;
for(i=0;i<=n;i++){
s=s+Integer.toString(i);
}
return s;
}
}
public void oddAndEvenNumbers(int num){
String
numinfo=quantifyToString(num);
String odd="";
String even="";
int i,j;
if(numinfo.length()<11){
for(i=0;i<numinfo.length();i++){
String s=numinfo.substring(i,i+1);
j=Integer.parseInt(s);
if(j%2==0){
even=even+s;
}
else{
odd=odd+s;
}
}
}
else{
for(i=0;i<10;i++){
String s=numinfo.substring(i,i+1);
j=Integer.parseInt(s);
if(j%2==0){
even=even+s;
}
else{
odd=odd+s;
}
}
while(i<numinfo.length()){
String s=numinfo.substring(i,i+1);
j=Integer.parseInt(s);
i++;
String s1=numinfo.substring(i,i+1);
i++;
int k=Integer.parseInt(s1);
j=j*10+k;
if(j%2==0){
even=even+s+s1;
}
else{
odd=odd+s+s1;
}
}
}
System.out.println("Odd Numbers: "
+ odd);
System.out.println("Even Numbers: "
+ even);
}
public static void main(String args[]){
Scanner s=new
Scanner(System.in);
System.out.print("Enter n:");
int n=s.nextInt();
OddAndEven obj=new
OddAndEven();
obj.oddAndEvenNumbers(n);
}
}
Output:
DO NOT USE ANY EXTERNAL LIBRARIES BESIDES BUILT IN JAVA LIBRARIES! KEEP IT SIMPLE!!! Provided Code:...
DO NOT USE ANY EXTERNAL LIBRARIES! KEEP IT SIMPLE!!! import java.util.Scanner; public class StoryTime { /*Method name : descrambler() @returns: String @param: int @param: String */ // Make your method here public static void main(String[] args) { StoryTime s = new StoryTime(); Scanner scn = new Scanner(System.in); System.out.println("Pick 1 for a joke or 2 for a Short Scary Story"); int input = scn.nextInt(); String str = "Juswert alois...
JAVA: Run length encoding is a simple form of data compression. It replaces long sequences of a repeated value with one occurrence of the value and a count of how many times to repeat it. This works reasonably well when there are lots of long repeats such as in black and white images. To avoid having to represent non-repeated runs with a count of 1 and the value, a special value is often used to indicate a run and everything...
Write a method called printReverse() that takes a string and uses recursion to print the contents of the string in reverse order. The string itself should not be reversed; it must be left in its original form. The method has the following header: void printReverse(String s, int i) where s is a reference to the string, and i is an integer parameter that you may use as you see fit. You do not need to code up this method as...
PLEASE HURRY Software Testing Don't make any changes to the provided code. Please write a test case for the below prompt using the provided java programs Use the setString() function in MyCustomStringInterface to set the value to “Peter Piper picked a peck of pickled peppers.”. Then test to see if reverseNCharacters() function returns the reversed string when the characters are reversed in groups of 4 and padding is disabled (in this case, “etePiP r repkcipa decep fo kcip delkpep srep.”)....
JAVA: amortization table: Hi, I have built this code and in one of my methods: printDetailsToConsole I would like it to print the first 3 payments and the last 3 payments if n is larger than 6 payments. Please help! Thank you!! //start of program import java.util.Scanner; import java.io.FileOutputStream; import java.io.FileNotFoundException; import java.io.PrintWriter; import java.lang.Math; //345678901234567890123456789012345678901234567890123456789012345678901234567890 /** * Write a description of class MortgageCalculator here. * * @author () * @version () */ public class LoanAmortization { /* *...
*** FOR A BEGINNER LEVEL JAVA CLASS, PLEASE KEEP CODE SIMPLE, AND WE USE BLUE J IN CLASS (IF IT DOESNT MATTER PLEASE COMMENT TELLING WHICH PROGRAM YOU USED TO WRITE THE CODE, PREFERRED IS BLUE J!!)*** ArrayList of Objects and Input File Use BlueJ to write a program that reads a sequence of data for several car objects from an input file. It stores the data in an ArrayList<Car> list . Program should work for input file containing info...
JAVA // TO DO: add your implementation and JavaDoc public class SmartArray<T>{ private static final int DEFAULT_CAPACITY = 2; //default initial capacity / minimum capacity private T[] data; //underlying array // ADD MORE PRIVATE MEMBERS HERE IF NEEDED! @SuppressWarnings("unchecked") public SmartArray(){ //constructor //initial capacity of the array should be DEFAULT_CAPACITY } @SuppressWarnings("unchecked") public SmartArray(int initialCapacity){ // constructor // set the initial capacity of...
Need help with this Java. I need help with the "to do" sections. Theres two parts to this and I added the photos with the entire question Lab14 Part 1: 1) change the XXX to a number in the list, and YYY to a number // not in the list 2.code a call to linearSearch with the item number (XXX) // that is in the list; store the return in the variable result 3. change both XXX numbers to the...
#1. Operators and values, expressions Please correct the following code to make it print the given expressions and their answers well (3pts). public class DataTypes { public static void main(String[] args) { System.out.println("5*8/6 = " + 5*8/6); System.out.println("(2*6)+(4*4)+10 = " + (2*6)+(4*4)+10); System.out.println("6 / 2 + 7 / 3 = " + 6 / 2 + 7 / 3); System.out.println("6 * 7 % 4 = " + 6 * 7 % 4 ); System.out.println("22 + 4 * 2 = "...
need help editing or rewriting java code, I have this program running that creates random numbers and finds min, max, median ect. from a group of numbers,array. I need to use a data class and a constructor to run the code instead of how I have it written right now. this is an example of what i'm being asked for. This is my code: import java.util.Random; import java.util.Scanner; public class RandomArray { // method to find the minimum number in...