How To Print Big Integer Using For Loop

Mar 6, 2015

I amtrying to iterate a value of L,R both are range of BigInteger but its not working

BigInteger L=in.nextBigInteger();
BigInteger R=in.nextBigInteger();
for (BigInteger bi =L;
bi<=bi.compareTo(R);
bi = bi.add(BigInteger.ONE)) {

//Task to do with Numbers
}

I am trying to iterate a for loop in range of L and R but its not working

View Replies


ADVERTISEMENT

Unable To Print A Loop Inside Array Of Greater Size Than Loop Itself

Jan 27, 2015

I am trying to print a loop inside an array of a greater size than the loop itself. Like for example I have an array of size 7 but it has only 3 elements.

int[] array=new int[7]
array[0]=2;
array[1]=3;
array[2]=4;

now what I want to do is print these three numbers in a loop so that my array[3]=2;array[4]=3;array[5]=4 ...... till the last one. Also the array could be any size and not just 7.

View Replies View Related

5 Digit Integer - Print If Input Number Is Palindrome Or Not

Apr 21, 2015

I have to write a program that inputs a 5 digit integer from the keyboard and prints if the input number is a palindrome or not. I got it to work, but when my result prints it says "0 is a palindrome" or "0 is not a palindrome". How can I get rid of the 0 and replace it with the number input by the user?

import java.util.Scanner;
public class Palindrome {
public static void main(String[] args) {
int number;
int digit;
int temp;

[code]....

View Replies View Related

Allow User To Enter Roman Numeral And Then Outputs Integer Number Value - While Loop

Feb 7, 2015

Write a program called RomanNumeralHelper that allows a user to enter a roman numeral and then outputs the integer number value. Use a Scanner to accept command line input from the user and continually ask for a roman numeral until the user enters Q (or q) to stop. Your solution should NOT use a switch statement.

Here is sample input / output:

Enter a roman numeral [Q | q to quit]: III
>> 3
Enter a roman numeral [Q | q to quit]: IV
>> 4
Enter a roman numeral [Q | q to quit]: V
>> 5
Enter a roman numeral [Q | q to quit]: Q
Good Bye!

This is what I have so far in my code, but I cant get what the user inputs when I want it to output the number.

import java.util.Scanner;
public class RomanNumber4
{
public static void main(String[] args) {
// obtain input from command window
Scanner input = new Scanner(System.in);
 
[Code] ....

View Replies View Related

Print A Diamond Using For-loop?

Mar 26, 2014

I am currently trying to print a Diamond using for-loops but I seem to be confusing my self / over-complicating it.

This is what I have so far [URL]). When I run the code I get [URL].

I want to duplicate it on to the other side but I can't seem to be able to figure out a working for-loop to print it out.

Also, is there a faster/efficient method of doing something like this?

View Replies View Related

While Loop To Print All Odd Numbers Between 1 And 100

Apr 3, 2015

I want to write a while loop to print all odd numbers between 1 and 100.

But it gives error. Where is the mistake?
 
public class pro {
public static void main(String[] args) {
// TODO Auto-generated method stub 
int c;
int x=1;
 
[Code] ....

View Replies View Related

Symbol Won't Print From For Loop

Oct 20, 2014

On line 45 i am trying to add "-" symbol to my output phone number. As of now the out prints like "1800*45*3569377. I want it to print 1800-3569377, or even more ideal: 1-800-356-9377. When printing normally (system.out.println) I can print symbols, but when I try to print from a for-loop it says "unclosed character literal." import java.util.Scanner;

public class Phone_010473030 {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.print("Enter a phone number string: ");
String Phone_num = input.nextLine();
Phone_num = Phone_num.toUpperCase();

[code]....

View Replies View Related

Print Variable Which Only Exists Within For Loop?

Jul 18, 2014

There's loads of problems with this. What I'm trying to do.

1) get a program to add the contents of an array together, preferably with a for loop and not the heavy handed version I've tried to use here.

2) get the for loop's output just once, since it won't compile or recognise the variable outside of the loop. How do I make the loop's 'counter' variable available everywhere?

public class retint {
 public static void main(String[] args){
int[] onetoTen = {1,2,3,4,5,6,7,8,9,10};
for (int i=0; i<10; i++) {
int counter = (onetoTen[0] + onetoTen[1] + onetoTen[2] + onetoTen[3] + onetoTen[4] + onetoTen[5] +
onetoTen[6] + onetoTen[7] + onetoTen[8] + onetoTen[9]);
 System.out.println(counter); 
}
}

Terrible code, I know. There has to be a more efficient way.

View Replies View Related

Print Triangle - Loop Is Not Working

Jul 7, 2014

I am trying to make a program that prints triangle... and I did various test on each method to realise that the problem lies with this segment.When I call this method, nothing prints out, I figure there is something with the loop that I am not realizing.the loop is backwards because it's supposed to have the right side edge parralel (when I try to print it out the spaces do not appear, imagine the x are space...), so as each line is looped the # of spaces diminishes

xxxx*
xxx*x*
xx*xx*
x*xxx*
*****

public class test {
public static void main(String[] args){  
for (int countdown = 5; countdown <= 1; countdown = countdown--){
showNTimes(countdown, ' ');
showNTimes(5- countdown, '*');
System.out.println("");
}
}
public static void showNTimes ( int nbTimes, char carac ) {
for ( int i = 1 ; i <= nbTimes ; i = i + 1 ) {
System.out.print( carac );
}
}
}

View Replies View Related

Program Ask For Five Names Using Loop Statement And Print All

Jan 24, 2014

write a program that would ask for the five names using loop statement and print all names .

View Replies View Related

Nested For Loop - Print Out Table Of Angles (sin / Cos And Tan)

Oct 1, 2014

I am working on my java program it prints out a table of angles and the sin, cos, and tan. For extra credit he wanted us to use nest loops to create a space after every five lines. I have come real close to getting this to work but have a problem with the very end of the table. The table needs to stop at 180...

public static void printTable(double angle,double sin,double cos,double tan) { // Method to create a table for the values
for (double j = 0; j <= 180;) {
for (double i = 1; i <= 5; i++) {//loop to print five lines of code
angle = Math.toRadians(j);

[Code] .....

Here is the end of the output of the table:

175.00.0872-0.9962-0.0875
176.00.0698-0.9976-0.0699
177.00.0523-0.9986-0.0524
178.00.0349-0.9994-0.0349
179.00.0175-0.9998-0.0175
 
180.00.0-1.00.0
181.0-0.0175-0.99980.0175
182.0-0.0349-0.99940.0349
183.0-0.0523-0.99860.0524
184.0-0.0698-0.99760.0699

View Replies View Related

For Loop - Print All Odd Numbers Between FirstNum And SecondNum

Feb 4, 2015

Prompt the user to enter two ints, firstNum and secondNum. Then print all odd numbers between firstNum and secondNum.

Here's my code-- my error is in this line: for(firstNum;firstNum<=secondNum;firstNum++)

The error is "not a statement."

import java.io.*;
import java.util.*;
public class ListOddNumbers
{
public static void main(String[] args) {
Scanner keyboard= new Scanner(System.in);
System.out.println("Enter your first number.");
int firstNum= keyboard.nextInt();

[Code] .....

View Replies View Related

Print Route Method / Stuck In A Loop Of Printing Same Two Nodes

Nov 13, 2014

My issue is that when I run my search, it does find a goal. However, when I try and print the route using my print route method, it just gets stuck in a loop of printing the same two nodes. What is wrong with My A* implementation?

package search;
import java.util.ArrayList;
import java.util.Collections;
import java.util.LinkedList;
 
[code]....

View Replies View Related

For Loop To Count Values Of Stack Of Quarters From 1.00 To 3.00 And Print Value Of Each Iteration

Nov 2, 2014

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)

[Code] ....

View Replies View Related

Invoke Some Methods In For Loop In Order To Print Some Info Stored In A List

Apr 28, 2014

I am trying to invoke some methods in a for loop in order to print some info stored in a List. But for some reason, compiler pops a message saying "cannot find symbol - method getEmpID(). You are using a symbol here (a name for a variable, method or class) that has not been declared in any visible scope." But I am pretty sure that method getEmpID (as also getName(), getAfm(), and payment() ) have been declared as public.

Note: My List contains objects of different type (SalariedEmployee, HourlyEmployee). I hope this is not the factor causing this problem.

Java Code:

import java.util.*;
abstract class Employee{
private String name = "";
private String afm = "";
private long EmpID;
static long count=0;

[code]....

View Replies View Related

Create Class Called Factorial Algorithm Which Will Compute / Print Factorial Of Integer Number On Screen

Dec 27, 2014

1)A factorial of a number X is equal to X*(X-1)*(X-2)*...*1.For example,3! is equal 3*2*1=6.Create a class called Factorial Algorithm which will compute and print the factorial of an integer number on the screen

2)Write a Java program to accept eight integers and a search element from the user and display whether the element is found or not.(Hint:use bubble sorting and binary search)

View Replies View Related

Can't Seem To Get Value For Integer 1 And Integer 2 To Pass With SetValue Method

Aug 10, 2014

public class MyInteger {
private int value;
public MyInteger(int number){
value = number;
System.out.println("Constructor created with value of " + value);

[code]....

I can't seem to get the value for integer1 and integer2 to pass with the setValue method. I get a runtime error stating the I need to have an int value for these two integers.

View Replies View Related

How To Make Print Employee Button To Print Info Of Other Class

Apr 12, 2014

Basically the class is supposed to have a static variable that keeps track of the number of companies (numberOfCompanies) that have been created and a static method that returns the value of this variable. I need to have a constructor and a method to addEmployee, a method to printCompany, and a toString method. The addEmployee method will check that there is only 1 salesperson, 2 designers, and 4 manufacturing persons at a time and will check that there are no more than 7 employees of the company.

The addEmployee method will return a String indicating what the error is (i.e. "There is already a sales person in this company") or a null if the employee was added. If attempting to name a third company, an error message will be shown. what i have so far but my print company mmethod returns null company class :in which i am obliged to use inputdialog because it says that it cannot return void when i use the showmeassage diaolog.

company class:

import java.util.ArrayList;
import javax.swing.JOptionPane;
public class Company {
private ArrayList<Employees> list ;
private static int numberOfCompanies;

[Code] ....

error message when print button is clicked:

Exception in thread "AWT-EventQueue-0" java.lang.RuntimeException: JOptionPane: parentComponent does not have a valid parent
at javax.swing.JOptionPane.createInternalFrame(Unknown Source)
at javax.swing.JOptionPane.showInternalOptionDialog(Unknown Source)
at javax.swing.JOptionPane.showInternalMessageDialog(Unknown Source)

[Code] ......

View Replies View Related

Two Threads - One Will Print Odd And Other Will Print Even Numbers In Sequence

Jul 25, 2014

I want to create two thread one thread will print odd number and another thread will print even number. but the number should be in a sequence like

1 2 3 4 5 6 7 8 9 10

View Replies View Related

While Loop Inside A For Loop To Determine Proper Length Of Variable

Feb 25, 2014

Here's the code: it's while loop inside a for loop to determine the proper length of a variable:

for (int i = 0; i < num; i++) {
horse[i]=new thoroughbred();
boolean propernamelength = false;
while (propernamelength==false){
String name = entry.getUserInput("Enter the name of horse "

[code]....

I was just wondering what was going on here -- I've initialized the variable, so why do I get this message? (actually the carat was under the variable name inside the parentheses.

View Replies View Related

When Type Quit To Close Outer Loop / It Still Runs Inner Loop

Nov 2, 2014

I have everything else working. My problem is that when i type "quit" to close the outer loop. It still runs the inner loop. The National Bank manager wants you to code a program that reads each clients charges to their Credit Card account and outputs the average charge per client and the overall average for the total number of clients in the Bank.

Hint: The OUTER LOOP in your program should allow the user the name of the client and end the program when the name entered is QUIT.In addition to the outer loop, you need AN INNER LOOP that will allow the user to input the clients charge to his/her account by entering one charge at a time and end inputting the charges whenever she/he enters -1 for a value. This INNER LOOP will performed the Add for all the charges entered for a client and count the number of charges entered.

After INNER LOOP ends, the program calculates an average for this student. The average is calculated by dividing the Total into the number of charges entered. The program prints the average charge for that client, adds the Total to a GrandTotal, assigns zero to the Total and counter variables before it loops back to get the grade for another client.Use DecimalFormat or NumberFormat to format the numeric output to dollar amounts.

The output of the program should something like this:

John Smith average $850.00
Maria Gonzalez average $90.67
Terry Lucas average $959.00
Mickey Mouse course average $6,050.89
National Bank client average $1,987.67

Code:

public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
String name = "";
int charge = 0;
int count = -1;
int total = 1;
int grandtotal = 0;
int average = 0;
 
[code]....

View Replies View Related

Convert From While Loop To For Loop

Mar 8, 2014

How to convert this program from a while loop to a for loop.

import java.util.Scanner;
public class LongDivision {
public static void main(String arguments[]){
Scanner input = new Scanner(System.in);
System.out.println("Enter the dividend: ");

[Code] ....

View Replies View Related

Converting For Loop To While And Do While Loop

Feb 17, 2014

How do I convert my for loop below to a while and do while loop?

for(int a=1;a<=9;a++){
for(int b=1;b<=a;b++){
System.out.print(a);
}
System.out.println();

[Code] .....

View Replies View Related

How To Store Value From Loop To Add To New Value From Loop

Feb 9, 2015

I am trying to make a program add values from a loop. So what its supposed to do is search through tokens on an imported file. The file lists State, Capital, and then capital population. Then take the population string, turn it into numbers, and then do stuff with the numbers. First I'm supposed to find the Highest and lowest population of the places in the file (which I did without problem), but the finally thing is I'm supposed to add each found population to the last so I can find the average of the populations.

I just cannot seem to grasp how to do that. I THINK I'm supposed to some how store the given value into a variable, but how do I get that variable to add to the new value?

like...?
Get token -> a
b = a
c = a + b

or wait no.....

Java Code :

import java.io.*;
import java.util.Scanner;
public class CapPopS
{
public static void main(String[] args) throws IOException
{
File stateCAP = new File("state-capital-2004population.txt");
if (!stateCAP.exists())

[Code] ....

View Replies View Related

How To Validate And Integer From 0 - 9

Nov 5, 2014

I created a GUI with a jTextField as an input box and am wondering how to validate that this data is an integer from 0 - 9. Here is what I have. However the if statement shows an error that says int cannot be dereferenced.

private void doneButtonActionPerformed(java.awt.event.ActionEvent evt) {
//Create and Initialize Variable
int category = Integer.parseInt(categoryInput.getText());
if (category.matches(0-9)); //int cannot be dereferenced error here
{

[Code]...

View Replies View Related

Integer Sum In Generics

Mar 20, 2015

What is wrong in this

class Gen<k,v>
{
K a;
V b;
Gen(K s, V f) {
a=s;
b=f;

[Code] .....

a is object of type k,then how can I retrieve content of a?

View Replies View Related







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