Good evening, I am having issue removing every positive multiple of five from my code. Here are the instructions :Output the numbers 1-1000, but make all numbers that are a multiple of five negative. Output a new line after each number.
Here is my code:
public class Example3 {
public static void main(String[] args) {
for (int counter = 1 ; counter <= 1000; counter++){
System.out.println(counter);
if (counter%5==0) {
System.out.println(counter*-1);
}
}
}
}
_________________________________________________________
my output is good until the i get something like this
5
-5
is there anyway to remove the positive multiples of five and keep the negatives multiples of five?
Thank you in advance.
Program:
public class Main {
public static void main(String[] args) {
for (int counter = 1 ; counter <= 1000; counter++){ // Loop runs from 1 to 1000
if (counter%5==0) { // Check the number is multiple of 5
System.out.println(counter*-1); // print the multiple of 5 in negative sign that is 5 is printed as -5 so on
}
else { // If number is not multiple of 5 then
System.out.println(counter); // print the counter
}
}
}
}
Output:

Good evening, I am having issue removing every positive multiple of five from my code. Here...
I am having a problem with my code. Here are the relevant parts. The method priceNow is supposed to take as an input a string in the form "Q1'20" (for example) and calculate the new price knowing that the price of the CPU decreases by 2% every quarter. Here is my class definition code: public class CPUv2 { private String launchDate; public CPUv2() { this.CPUGeneration = 1; this.CPUSeries = "i3"; this.suggestedPrice =...
I am working on java patter. my code read the string and it will get only the numbers. in this case,124,140,130..but i want to get the maximum number. which is 140. I would appreciate any kind of help. This is my code public class questions { public static void main(String[] args) { int total=0; String test="it tookthismuch total time: 124. it tookthismuch total time: 140. it tookthismuch total time: 130. "; ...
I am trying to run a couple of functions in my main and It won't output anything if there is anything that you see wrong please help me out. I have to use simple, sometimes slower ways because we can use what we haven't learned yet. Here is my code. package a3; import java.util.Scanner; public class LoopsAndImages { public static void main(String[] args){ String test = "A rabbit has a carrot"; Boolean numbers = hasMoreEvenThanOdd("12344"); System.out.println(test); System.out.println(hideLetterA(test)+" This is the...
last question : Don't be negative
and source Code : of don't be negative
Repeat the assignment "don't be so negative" except solve the problem using recursion. Specifically, create an array of 10 random integers between -10 and +10 then create a method say "findNegatives" that takes as input parameters the array, and possibly other parameters, then calls itself (direct recursion); method find Negatives( ...method parameters here...) ...some stopping criteria... find Negatives(...method parameters here...) Output: Array position #0 #1 Value...
Hey guys! Huge part of my grade !! My code works already but I need it so it references to my node list class instead of my array, what would I need to change? My assignment was to create a list from an assignment when we used an array, but I cant make it to work without the array, help! The professor said it was okay to either keep the array or to delete it altogether. package zipcode; import java.io.File; import...
Below is the code for the class shoppingList, I need to enhance
it to accomplish the challenge level as stated in the description
above.
public class ShoppingList {
private java.util.Scanner scan;
private String[] list;
private int counter;
public ShoppingList() {
scan = new java.util.Scanner(System.in);
list = new String[10];
counter = 0;
}
public boolean checkDuplicate(String item) {
for(int i = 0; i < counter; i++) {
if (list[i].equals(item))
return true;
}
return false;
}
public void printList() {
System.out.println("Your shopping...
Java programming question: Here is the feedback I received "sort fails. Use Arrays class method to sort." The actual question: Write a program as follows: Declare a five element array of Strings. Use a for loop and keyboard input to populate the array with the names of five friends. Sort the array in alphabetical order. Use a foreach loop to print the sorted array of friends, all on one line. Sample Output (inputs in italics) Enter the names of five...
Java Help Please: I'm doing something wrong with my while loop. I want my code to check the phone number that is input to make sure it matches. If it doesn't I want it to print out Error! and I want my While loop to ask the user to try again by inputting another phone number. When the user puts in a phone number that matches I want the program to continue to output my tokens. When I run this...
I am given an input file, P1input.txt and I have to write code to find the min and max, as well as prime and perfect numbers from the input file. P1input.txt contains a hundred integers. Why doesn't my code compile properly to show me all the numbers? It just stops and displays usage: C:\> java Project1 P1input.txt 1 30 import java.io.*; // BufferedReader import java.util.*; // Scanner to read from a text file public class Project1 { public static...
I am going to show you my code and for some reason when I addDomino to front, my program gives me a null value, I need help figuring out why. public void addDominoFront(String d){ String temp1 = Domino[0]; String temp2; Domino[0] = d; for(int i = 1; i< numDominoes; i++){ temp2 = Domino[i]; Domino[i] = temp1; temp1 = temp2; } numDominoes = numDominoes +1; } The I have the following...