Creating A Method That Reverse Digits Of Numbers

Feb 23, 2015

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

View Replies


ADVERTISEMENT

Creating A Reverse List - Integer - Using Recursion

Jan 2, 2015

I created this code, seems like it should be working properly and the code is right, but the output is not what it should be.The action gets a List<Integer> and should make it reversed.

As example: 1 2 3 4 5 ---> 5 4 3 2 1

The Nodes in the new list (lst2) should be in a reversed position.The code does compile with no errors.I do have Node<T> and List<T> classes

Java Code:

public class NodeReverse
{
public static void reverse (List<Integer> lst, Node<Integer> node, int counter, List<Integer> lst2, Node<Integer> pos) // Should make lst = lst2 while lst2 is the opposite to lst
{
node = node.getNext();
counter++;
if(node.getNext()!=null)
reverse(lst, node, counter, lst2, pos);

[code]....

View Replies View Related

Reverse Numbers Using Java Arrays

Feb 27, 2014

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: ");

[Code] .....

View Replies View Related

Order Of Numbers - Reverse Array Program

Apr 23, 2015

import java.util.Scanner;

public class ReverseOrder {
public static Scanner input = new Scanner(System.in);
public static void main(String[] args){
int[] numbers;
double[] reverse;

numbers = readArray();
reverse = reverseOrder(numbers);

[Code] ....

I have to write a program that takes an order of numbers and print the reverse order of those numbers.

the out put i receive is:

How many numbers do you want to enter?
4
Please enter 4 integers separated by a space:
1 2 3 4
Your numbers in reverse order are:[D@1f96302

View Replies View Related

Encryption / Decryption - How To Separate Digits To Make Numbers Encrypted

Nov 4, 2014

I've written most of the code (along with another classmate) to get this to work, but I can't seem to return the encrypted value. I'm also trying to figure out how to separate the digits (or if I'm supposed to) to make the numbers encrypted. The main kicker is that we have to be using methods to return the final values. Everything compiles, (It compiles, but no results really.)

A company wants to transmit data over the telephone, but they are concerned that their phones may be tapped. All of their data is transmitted as four-digit integers. They have asked you to write a program that will encrypt their data so that it may be transmitted more securely. Your program should read a four-digit integer number and encrypt it as follows: Replace each digit by the remainder after (the sum of that digit plus 7) is divided by 10. Then, swap the first digit with the third, and swap the second digit with the fourth. Then print the encrypted integer. Do the encryption in a method and send the encrypted number back to main.

Here are the method headers: public static int encrypt(int num) // Takes num as a parameter and returns the encrypted value public static int getnum() // gets one number from the user Example: If the user enters 1234 they should see: 0189

import java.util.Scanner; //Needed for Scanner class
public class LNFI_LNFI_program2
{
public static void main(String[] args)
{
getnum(); //Calls for getnum() method

[Code] ....

View Replies View Related

Ask User To Store 10 Numbers In Array - Print In Order Entered And Reverse

Apr 15, 2014

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?

View Replies View Related

Floating Point Numbers - Print Contents Of Array In Reverse Order

Feb 27, 2014

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;

[Code] .....

View Replies View Related

For Loops Reverse Method

Oct 29, 2014

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);

View Replies View Related

User To Input Integer And Then Outputs Both Individual Digits Of Number And Sum Of Digits

Feb 2, 2015

Goal is to: Write a program that prompts the user to input an integer and then outputs both the individual digits of the number and the sum of the digits.

First I don't know where I made mistakes here, and the only error it finds right now is that str2 was not initialized and I cannot figure out where/when to initialize it.

import javax.swing.JOptionPane;
public class DigitsAndSum {
public static void main (String[] args) {
String str1;
String str2;
int int1 = 0;
int int2 = 0;

[Code] ....

View Replies View Related

Using Split Method To Reverse A String

Oct 19, 2014

In this exercise, create a program that asks a user for a phrase, then returns the phrase with the words in reverse order. Use the String class's .split() method for this.

Example input
The rain in Spain falls mainly on the plain

Example output
plain the on mainly falls Spain in rain The

While I understand the assignment, nowhere in the text is it covered how to reverse the order of the words in the string. I understand using the .split method, but not for this exercise.

Here is my code so far.

import java.util.*;
/**
* Java class SplitString
* This program asks for a phrase, and the code allows the phase to return in reverse order.
*/

public class SplitString {
public static void main (String[] args){
//set phrase input and mixed which will be the result

[Code] ....

As you can see, I have been googling this method and have come up nearly empty. My text does not cover the .reverse() method. The only thing it covers with .split() is how to split a string. I also tried StringBuilder with no success.

View Replies View Related

Creating A Setter Method?

Aug 28, 2014

so here's my code

import java.io.*;
public class Movies {
public String title;
public String director;
public String theme;
public Title(String title)

[code]....

the error is in line 9 which is

public Title(String title)

and the error is (error: invalid method declaration; return type required)

View Replies View Related

Creating A Method That Resembles ArrayList

Jan 21, 2015

I'm writing a program that acts as a 'pocket' where the user is able to enter a kind of coin, such as, a quarter and the amount of quarters it has. I was assigned to do 3 different class, the Coin Class in which the coins and their values can be instatiated from, a Pocket Class, where I have to write a method that can add the coins of the user (basically the method would act like ArrayList .add() ) and the PocketClass tester. I have already written most of the code, but I am stuck as to how I could write the following method:

Java Code:

public void addCoin(String s, int i) {
// s is type of coin, you are using s to instantiate a Coin and get value
// i is number of coins, you are using i to keep adding value to the totalValuefor
} mh_sh_highlight_all('java');

Would I use a for-loop in order to keep track of the number of coins? I would use ArrayList but the assignment calls for creating a method similar to that of .add()

View Replies View Related

Creating Enum With String And Method

Nov 9, 2014

How would I go about and make an enum, that has Strings and Methods?I want to make a class called GraphicalEffects, this class and be instanstiated and it has a method to apply graphicalEffects AS methods or some type of references to methods in an ArrayList.

View Replies View Related

BlueJ - Creating New Variable From Within A Method

Mar 29, 2014

I am using blueJ as my java editor.

If I have a method that creates a new variable (the name of which is a string argument for the method). Can I get that variable to appear in the workspace in the variables pane?

So instead of just using return to output the variable how do I get in that variables pane?

View Replies View Related

Creating Method To Print Array Of Integers

May 7, 2014

I am trying to create a method that takes an array of integers and prints it out using System.out.print. I'm having trouble creating the right way to print it out since I cannot find a way to convert the int array to a string to print it out.
 
public static String printArray(int[] num){
for (int i=0; i<num.length;i++){
String msg = num[i];
}
return System.out.print(msg + " ");
}

View Replies View Related

Creating Applet With Dropdown Lists - Method Not Abstract

Oct 21, 2011

i am trying to create an applet with drop-down lists. When I compile the program the following error message appears '. . .is not abstract and doesn't override abstract method action Performed. . . Here is my code . . .

import java.awt.*;
import java.awt.event.*;
import java.applet.*;
public class DavidApplet extends Applet implements ActionListener //class header {
Label fName=new Label("First Name");

[Code] .....

View Replies View Related

Creating Equals Method To Compare Strings In A Class?

Mar 26, 2015

How would I create a equals method to compare strings in a class that I'm creating. I need to create the method in my class, and then call it in a driver. How would I do this?

View Replies View Related

Creating A Static Method That Requires No Arguments And Returns No Values?

Sep 28, 2014

I am doing an assignment and I am clueless as to what I did wrong or supposed to do in terms of placement of coding.

This is what I supposed to do:

1.) Type the following shell for the class:

public class ParadiseInfo
{
}

2.) Between curly braces of the class, indent a few spaces and create the shell for the main() method:

public static void main(String[] args)
{
}

3.) Between the braces of the main()Method, insert a call to the displayInfo() method:

displayInfo();

4.) Place the displayInfo() method outside of the main() method, just before the closing curly brace for the ParadiseInfo class:

public static void displayInfo()
{
system.out.println ("Paradise Day Spa wants to pamper you.");
system.out.println ("We will make you look good.");
}

This is what I attempted to do:

I know it is wrong I am just clueless on where to put the code and why

public class ParadiseInfo
{
displayInfo();
public static void main(String[] args)
{
public static void displayInfo();
}
system.out.println("Paradise Day Spa wants to pamper you.");
system.out.println("We will make you look good.");
}

--- Update ---

I also tried it this one and ended up with 1 error..

public class ParadiseInfo
{
displayInfo();
public static void main(String[] args)
{
}
public static void displayInfo();
{
system.out.println("Paradise Day Spa wants to pamper you.");
system.out.println("We will make you look good.");
}
}

View Replies View Related

Getting Error While Creating A Method - Void Is Invalid Type For Variable

Jun 25, 2014

I am new to Java and trying to learn it.I wrote the following program but while creating the method nav i am getting errors.

Error:- void is an invalid type for the variable nav

import org.openqa.selenium.*;
import org.openqa.selenium.firefox.FirefoxDriver;
import java.util.*;
public class YahooHomepage {
private static WebDriver driver;

[Code] .....

View Replies View Related

Add Numbers Using Pencil Method

Dec 2, 2014

I'm trying to do a program where I add numbers using the pencil method (i.e. add 9 + 5 and get 14, carry the 1, drop down the 4).

import java.io.*;
import java.util.Scanner;
public class add_arrays
{
public static void main(String[] args)
{
Scanner input = new Scanner(System.in);
String s1, s2;

[code]...

View Replies View Related

Method That Shuffles Array List Of Numbers

Jan 27, 2015

Write the following method that shuffles an array list of numbers.

public static void shuffle(ArrayList<Number> list)
package shuffleArrayList;
import java.util.ArrayList;
import java.util.Arrays;
public class ShuffleArrayList
{
public static void main(String[] args)

[code]....

View Replies View Related

How To Convert Numbers Into String Without Using Array And Method

Feb 12, 2014

How to convert numbers into string without using an array and a method ....

Example of arrayed code:

The code here is working but i want to use the other way for not using array just like switches and if and loops only.
I made a code here but i did'nt run what i want to output .....

package UnderPackage;
import java.util.Scanner;
 public class NumberToWords {
static Scanner input = new Scanner(System.in);
public static void main(String[] args) { 
int number;
int b;

[Code] ....

View Replies View Related

Copying Random Generated Numbers To Selection Sort Method

Mar 19, 2015

Java Code:

import java.util.ArrayList;
import java.util.Random;
public class NumSorting {
public static int numOfComps = 0,
numOfSwaps = 0;
public static void main(String[] args)

[Code] ....

What is wrong with my code in this sorting program? It won't copy the random generated numbers to the sort method. How to get the random generated numbers to copy to the sort method. Below is what the program is displaying.

Original order : 3 2 5 4 1

Selection Sort

Original order:

[I@7a84e4

Number of comps = 10

Number of swaps = 0

Sorted order : 0 0 0 0 0

View Replies View Related

Method To Take Array Of Integers And Rearrange Numbers From Least To Greatest Using For Loops

Apr 22, 2014

I'm making a method to take an array of integers and rearrange the numbers from least to greatest, using for loops.

I'm getting the error "java. lang. ArrayIndexOutOfBoundsException: 8,

Portion of the ArrayMethods class with the sorting method

Java Code:

public static Integer[] sortArray (Integer[] a)
{
int swap;
for (int i = 0; i < a.length; i++)

[code]....

View Replies View Related

Method To Format Telephone Numbers - String Index Out Of Range Error

Jan 25, 2015

I'm trying to put together a method that formats telelphone numbers, but there's a part of my code that not working. If I enter (305)912-5458 into the variable phoneNumb I get an index is out of range error. I added a lot of system out messages so that I can try to get an idea of why the code was crashing.

public static void main(String[] args) {
int intBegin = 0;
int intEnd = 1;
int length;
String charact;
StringBuilder numbuilder = new StringBuilder();

[Code] .....

The error message I'm getting is:

run:
The length is 13
intBegin is at 0
intEnd is at 1
index is at 0
Charcter ( was not inserted

[Code] ....

View Replies View Related

Creating Method That Prints The Square Root Of A Number Up To A Certain Number?

Feb 27, 2015

I am trying to create a method that prints the square root of a number up to a certain number. It needs to take a single int parameter for example "n" , and then print all of the (positive) even perfect squares less than n, each on a separate line. I want the method to be called something like this:

public void Squares(int n) {
}

I need the output to look something like this:

Example: if n = 40, your code should print

4
16
36

So I have been working for a few hours now and am really stuck.

This is what I have so far:

int count = 0;
int n = 4;
int max = n;
while(count < max) {
System.out.println(n);
n = n * n;
count++;

View Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved