I'm having problems with the mid section of the rocket, specifically the bottom part of the mid section:
|../..../..|
|.//..//.|
|//////|
I'm having difficulty writing the for loop to correctly print the dots. You're supposed to incorporate a constant which allows you to adjust the size of the overall figure. The loop doesn't work when I adjust the size, only when the value of HEIGHT is 3. The loop, however, for some reason works with the top part of the mid section.
This is the for loop for the top section.
for (int dots = 1; dots <= -1 * line + 1 * HEIGHT; dots++) {
System.out.print(".");
}
This is the for loop for the bottom section.
for (int dots = -1 * line + 1 * HEIGHT; dots <= 1; dots++) {
System.out.print(".");
}
Usually reversing the iteration of the loop just requires flipping the conditions, right? But it didn't work this time for some reason. Why this doesn't work? I can post the code to my entire program for compiling.
I had to write a foor loop to count the values of a stack of quarters from 1.00 to 3.00 and I had to print the values, that I understood and got it working so I taught the next assignment was going to be easier but I am having a hard time with it. For this one I have to write a for loop to print all the positive integer factors of 144 and I am supposed to print of factor per line but I tried doing that but it doesn't work it just prints out 144.
This is my code. The quarter assignment is also in there because it is part of a lab so just ignore that part since it is working correctly.
public class ForLoopPractice { public static void main(String [] args) { // Write a for loop to count out the values of a stack of quarters from $1.00 to $3.00 // Print the value of each iteration. Print this all on one line, rounded to the nearest cent. // To print rounded, use printf, with a placeholder of %.2f // (%f is the floating-point placeholder; the .2 indicates the number of decimal places) /* YOUR CODE HERE */ for (double q = 1.00; q <= 3.00; q += .25)
I'm trying to make a piece of code that writes a for Loop program using OOP. I need to create a class, name that class and have it contain several reverse methods and use a runner class to test it.So far this is the code I've come up with. Does it work or not?
public class loopDemo{ public static void main(string[]args){ String alphabet = "abcdefghijklmnopqrstuvwxyz"; public String reverse(){ char myBoi; int myIta; String tebahpla for(myIta=25j i>=0 ji++){ tebahpla+= alphabet.charAt(myIta);
how a nested for loop increments the outer loop and then the inner loop and then when it runs the inside code.I've ran the program a few times but I'm just not understanding it, need little narrative to it?
I need to write a class,that will give me output like this:
* *** **** *** *
I have to use for loop,i know that i have to use nested for loops, for rows and columns. I just cant figure it out the thing with spaces,and how to turn it to count back.
Im trying to create a checkerboard pattern with 2 nested for loops . I need to output asterisk characters. Im supposed o use an n int so I dont know if im limited to that 1 int. Im only getting 1 line of asterisk.
* * * * * * * * * * * * * * * * * * * * package checkerboard; public class Checkerboard { public static void main(String[] args) { for (int row = 1; row < 6; row++){ System.out.print("* "); for (int col = 6; col < col; col++) {
// Demonstrate a two-dimensional array class TwoDArray { public static void main(String args[]) { int twoD[] [] = new int[4] [5]; int i, j, k = 0;
[Code] .....
Output:
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
(1) I don't understand how repeating the loop creates the structure of the output. Taking the second loop away and putting the "System.out.print(twoD[i] [j] + " " );" under k++ creates the output to print a number on each line. How do I write the code not having the second loop, assigning k to each value that is moved through the grid then printing it out but having the output the same?
So I cant figure out why my output for my for loop isn't working properly. So the output for the square comes out right but the for loop isn't working properly for the H. I have tried to figure it out and it should go to the next line but its not.
import java.util.Scanner; public class Random { public static void main(String [ ] args) {
I wrote this (for the variable name, this is just a small part of my program and I'm trying to get the pattern right so I didn't mind my variables at the moment):
Java Code:
public class NewFile{ public static void main(String []args){ int k = 0; for (int i=1 ; i<=5 ; i++) { { for (int h=2 ; h >= i ; h--)
I realize I should divide the code into a lower and upper triangle using two loops. However, I don't know how to break the first part. I did find the "trend" but I don't see how to implement it.
Question: 1. Declare and implement a class named Substrings. The class will contain the following data members and methods:
Data members: string S
Methods: setS() take a string as a parameter and store it in S printSub1(), printSub2(), printSub3(), printSub4() print all substrings of S. If S = "abcd",
Alright so after doing some googling and watching tutorials I managed to put together the first two but I still don't exactly understand how nested for loops work, however just a single loop I do understand.
Secondly, the 3rd and 4th prints are completely destroying my brain using for loops, which we are supposed to use. Check out my code below, also keep in mind the 3rd is giving errors and the 4th i had to revert back to the same as the first print temporarily because my code because so messed up. How to understand nested for loops better.
[code=Java]
import java.util.Scanner; class subString { String S; void setSubstring(String SS) { S = SS;
[Code] .....
Compiling: error for myS.printSub3 and myS.printSub4 is the same as 1 because i had to revert it after ruining the code.
So basically i have to read from a text file and get some information back from that and print to screen. Im quite confused and im not sure what loop i should use first to scan the text and receive certain information back?
Nested for-loops always throw me in a loop.I found a snippet that uses 2 for-loops to check if there is a duplicate element in the array:
/* * brute force way of checking if array contains duplicates in Java comparing each elements to all other elements of array complexity on order of O(n^2) not advised in production */ public static boolean bruteforce(String[] input) { for (int i = 0; i < input.length; i++) { for (int j = 0; j < input.length; j++) { if (input[i].equals(input[j]) && i != j) { return true; } } } return false; }
Let us say we have: String[] input = new String[] {"one","two","three","one"}
When input validation for the first months rainfall is non-negative, this results in correct average rainfall.
When input validation is used for the first months rainfall I'm prompted to input a positive number, which is 2.
When asked to input rainfall, in inches, for each month, I begin with input -3, I am again prompted to re-enter a positive, I enter 3. What happens is, whichever positive integer I input after I had entered a negative for the first months rainfall, the average would be off by the positive number inputted.
package averagerainfall; import java.util.Scanner; public class AverageRainfall { public static void main(String[] args) { int maxYears; int totalMonths;
This code is supposed to convert a decimal base number to base 2, 8 or 16. It prints the number but it's supposed to be in the reverse order for example when converting 188 to base 16. it prints CB instead of BC.
package test; import java.util.Scanner; public class Test { public static void main(String[] args) { Scanner input = new Scanner(System.in); System.out.println("Enter a positive integer."); int number = input.nextInt();
Write an application, HiFour that prompt for four names and then prints the greetings, but with the names in reverse order and with punctuation as shown in the example.
I have a college question ask me to write a class StringRevert which does the following:
-prompting user for an interger n -creating an array of n string -repeatedly read character string from user input and store them in the array until end of array is reached or user input -quit(quit should not saved in array) -print the string from array in reverse order, from last enter to first enter. -assume user always supplie correct input
This is what I've done so far but how to get it working.
import java.util.Scanner; public class StringRevert { public static void main(String[] args) { Scanner in = new Scanner(System.in); System.out.println("enter value of n: "); int n1 = in.nextInt(); String[] n = new String[n1];
We were given a class lab that asks us to write a program that create a multidimensional array ( 5 x 5 ), populates the array using nested loops with letter from A until Y, and displays the array to the screen. and the result should look like this:
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
How to write this program.. I have tried all my best but the results are not coming like this..
Write a Java program that asks the user to store 10 numbers in an array. You should then print the array in the order entered and then print in reverse order. However, instead of putting all the information in the main, you should use a class called PrintIt. The PrintIt class should have an instance variable that is an array to hold the numbers. You should have a method that will print the array in the order entered. You will also need a method to print in reverse oder. Then create a tester class that asks the user to enter 10 numbers and puts them in an array.
So far I've got this.
public class printIt { int i; int [] numArr = new int [10]; public printIt () { i = -1;
[Code] .....
Output:
Enter a number:
8 34
Forward:
8 34
Reverse:
34 8
end
what i want as an number is being able to print out 10 numbers but this only lets me do two numbers. Why is that so?
I am trying to do this assignment but I can't get the needed output.
Create a program that asks the user how many floating point numbers he wants to give. After this the program asks the numbers, stores them in an array and prints the contents of the array in reverse order.
Program is written to a class called ReverseNumbers.
Example output
How many floating point numbers do you want to type: 5
Type in 1. number: 5,4 Type in 2. number: 6 Type in 3. number: 7,2 Type in 4. number: -5 Type in 5. number: 2
Given numbers in reverse order:
2.0 -5.0 7.2 6.0 5.4
Java Code:
import java.util.Scanner; public class apples { public static void main(String[] args) { Scanner reader = new Scanner(System.in); double[] numbers;