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
My code:
import java.util.Scanner;
public class apples {
public static void main(String[] args) {
Scanner reader = new Scanner(System.in);
double[] numbers;
System.out.print("How many floating point numbers do you want to type: ");
I am trying to write a code that allows you to input 2 lists and it tells you if they are identical or not. However, when I enter my fist list I can only enter two values and then it asks for the next list. How would I fix this to allow me to enter more than two values?
Also, If the second list is different it has me enter more values that list one.
public static void main(String[] args) { Scanner input = new Scanner(System.in); // Enter values for list1 System.out.print("Enter list1: "); int size1 = input.nextInt(); int[] list1 = new int[size1]; for (int i = 0; i < list1.length; i++) list1[i] = input.nextInt(); // Enter values for list2 System.out.print("Enter list 2: ");
I've just written a program that generates 100 numbers that range from 0 ~ 25 using arrays, the program calls another method that sorts the even numbers into a separate array and returns the array. I need it to display both arrays, however, when I run my program, the numbers of both arrays are mixed together, and I'm not sure how to separate them.
[ public class Array1 { public static void main(String[] args) { int array [ ] = new int[100]; for (int i = 0; i < array.length; i++) { array[i] = (int) (Math.random() * 26);
Create an integer array with 10 numbers, initialize the array to make sure there are both positive and negative integers. Write a program to generate two arrays out of the original array, one array with all positive numbers and another one with all negative numbers. Print out the number of elements and the detailed elements in each array.
public class problem3 { public static void main(String[]args){ int[] numbers = {1, 2, 3, 4, 5, -1, -2, -3, -4, -5}; for (int i = 0; i<numbers.length;){ if(i>0){ System.out.println(numbers); } else System.out.println(numbers); } } }
I am trying to create a method that reverses the digits of a number.
import java.util.*; public class KDowlingWeek7 { static Scanner console = new Scanner (System.in); //Scanner input = new Scanner(System.in); public static void main(String[] args) {
[Code] .....
The error I get is :
Error: cannot find symbol System.out.print(reverseDigit + " "); Symbol: variable reverseDigit Location: class KDowlingWeek7
public class ReverseOrder { public static Scanner input = new Scanner(System.in); public static void main(String[] args){ int[] numbers; double[] reverse;
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;
I want my function to return an array, with the array holding just the values of data that appear in good.
This is what should be returned:
{3, 5, 3, 2, 3, 3}
What is currently being returned:
{0, 3, 5, 3}
I didn't want to miss any numbers, so I decided to iterate through j for the "good" array, and then just i for the one that I was looking for matching numbers. Perhaps part of the problem is that if the condition is met, it goes to the next iteration of the loop. I'm not sure.
public class Arrays2 { public static void main(String args[]){ int [] data = {8, 3, 5, 3, 7, 2, 8, 3, 3 }; int [] good = {5, 2, 3, 2}; int [] result = f2(data, good); for (int i = 0; i < result.length; i++){
Write a program to maintain a list of the high scores obtained in a game. The program should first ask the user how many scores they want to maintain and then repeatedly accept new scores from the user and should add the score to the list of high scores (in the appropriate position) if it is higher than any of the existing high scores. You must include the following functions:
-initialiseHighScores () which sets all high scores to zero.
-printHighScores() which prints the high scores in the format: “The high scores are 345, 300, 234”, for all exisiting high scores in the list (remember that sometimes it won’t be full).
-higherThan() which takes the high scores and a new score and returns whether the passed score is higher than any of those in the high score list.
-insertScore() which takes the current high score list and a new score and updates it by inserting the new score at the appropriate position in the list
public class ReverseString { public static void main(String args[]) { //quick wasy to reverse String in Java - Use StringBuffer String str = "The rain in Spain falls mainly on the plain"; String revString = new StringBuffer(str).reverse().toString();
[Code] .....
The requirements: The program runs but for some reason it is not meeting the requirements. use the String method toCharArray and a loop to display the letters in the string in reverse order.
This is what I have to do:Write a program that takes a string of someone's name and prints it out last name first. Your program must use pointers, not array subscripts. You may use the available string manipulation functions if you find an opportunity.
Example:
"George Washington" "Washington, George"
I am not sure how to reverse the name, I have been looking in my textbook and online and cannot figure it out. This is what I have put together so far, it does not run. At the end it says unnecessary return value.
import java.util.*; import java.util.Scanner; public class Test { public static void main ( String [] args ) { Scanner sc = new Scanner(System.in); System.out.print("Enter name: "); String name = sc.nextLine(); String lastname = ""; String firstname = ""; for(int i = 0; i < name.length(); i++) { if(name.charAt(i) == ' ')
I am creating a recursive method to reverse a linked list in java. It works the first time when I call it, but I want it to work where I call it a second time and it reverses it to the original state. How can I get that to work with this implementation?
public void reverseList() { System.out.printf("%-16s%-3s%n", "Name", "Score"); System.out.println("--------------- -----"); reverseList(first); } public void reverseList(Node aNode) { if (aNode != null) { reverseList(aNode.next); System.out.printf("%-15s%6s%n" , aNode.name , aNode.score); } }
My assignment about writing a java code which will convert a input java code to its respective class diagram, object, sequence , use case and activity diagram. I have worked only on restructuring of input java code till now and still I have lots to do.I'm looking forward for a reply expecting at least one code generating at least one UML diagram.
The users of our a enterprise Java based web application must access a third web application through simple HTML links and then navigate in the target application. But for security reasons and constraints the direct exchange between the browers of users and server of the other web application is not allowed. Our web application must retrieve the web page from the other application and must return it to the users's browser. Is there a convenient way to implement this requirement in J2EE ? In this case our web application must play the role of a simple reverse proxy, must request a target JSP page from other application and process it to rewrite the URLs contained in the HTML page, then send the response to user's web browser.
I have the following double linked list and I'm supposed to order it descending (reverse) using the printInReverse() method; since the list orders itself ascending when the numbers are added, how could I order it descending in this method? Here's the code without implementing descending/reversing methods:
I mainly would like to know is a int[4][4] or a int [4*4] is more efficient to use. Which takes more storage? Which requires more to process? that kind of stuff.
So like, in lua programming language you can do things like,
Array = {1, 2, 3, abc = 5, efg = {123, 456, 789, hij = {"tests","works!"}}, hij = true}
Array[1] = 5
Array[3] = true
Can you do atleast something like this in java or?
I would like to do this because if let's say I was making a game, I could define what tiles are passable and which are not and then their location or something, so like this:
//p (passable) stands for if possible to walk on //c stands for tile image t = ["grass.png","water.png","chest.png"] Tiles = [ [p = false, c = t[1], x = 3, y = -2 ], [p = true, c = t[0], x = 4, y = 3 ],
I have a project for a class where I'm supposed to be something with private arrays and private integers and I still don't understand the point of private anything within java. if I want to change a variable I'll change it. if I want it to stay the same I'll leave it the same. so what point is all this private/public nonsense unless I'm trying to stop hackers or something?
I have to write a program that takes an array of grades and calculate the average and then count the number of grades that are above average and also count the number of grades that are below average. This is what I have so far, it calculate the average and tells me how many are above average... where and how do I get to count how many are below average
public class arrays{ public static void main(String[] args) { final int grades = 5; double[] numbers = new double[grades]; double sum = 0;
public static void main(String[] args) throws FileNotFoundException { // create data file to read from File inf = new File("cityPopulationData.txt"); //Create a file to write out to. PrintWriter fileOut = new PrintWriter("output.txt");
[Code] .....
This is my error
Exception in thread "main" java.util.InputMismatchException at java.util.Scanner.throwFor(Scanner.java:909) at java.util.Scanner.next(Scanner.java:1530) at java.util.Scanner.nextInt(Scanner.java:2160) at java.util.Scanner.nextInt(Scanner.java:2119) at PA9.getData(PA9.java:35) at PA9.main(PA9.java:22)
Write a Java program to read from the data file, find the city with the highest population based on the 2010 census data, the city with the highest population growth from 2010 to 2013, the city with the lowest population growth from 2010 to 2013, and the city with the highest density (number of persons per sq. mile).
I am having some trouble with a Java program. I have a txt data file, which I will display, that I need to add into two separate arrays. The text file is 8 lines long that is supposed to go into two separate 4x4 matrices. A little background info on this program, reads in two arrays, compares them and outputs the largest elements of the same index and outputs them in a separate array. I somehow cannot seem to figure out how to do this. My code is below:
Recently I have missed a few weeks of my class due to family emergencies. Because of this I have missed very important lectures. My professor has assigned me the following assignment:
Prices Write a Java program that specifies three one-dimensional arrays names price, amount, and total. Each array should be capable of holding 10 elements. Using a loop, input values for the price and amount arrays. The entries in the total array should be the product of the corresponding values in the price and amount arrays. After all the data have been entered, display the following output:
Total Price Amount
==== ==== ======
Under each column heading display the appropriate value.
I know how to display everything using printf, how to create the actual arrays and define the array size, but I am confused on how and what loop to use and how to construct it. This is what I have managed to write up so far:
import java.util.Scanner; // Imports the Scanner class import java.text.DecimalFormat; // Imports the DecimalFormat class
public class Prices { public static void main(String [] args) { double[] price = new double[10]; double[] amount = new double[10]; double[] total = new double[10];
// Create a new Scanner object Scanner keyboard = new Scanner(System.in); } //End of main method } // End of public class