Print N Number Of Armstrong Numbers

Mar 27, 2014

Where I am doing mistake to print the numbers of Armstromg numbers requested.

import java.util.Scanner;
public class ArmStrongNumber {
public static void main(String[] args) {
// TODO Auto-generated method stub
int x, y, z=0, temp, temp1=1;

[Code] .....

View Replies


ADVERTISEMENT

Program That Takes User Odd Number And Print Prime Numbers Lower Than User Input

Nov 4, 2014

I have been struggling with this program for weeks. This program is supposed to take a user's inputted odd number and then print out all prime numbers lower than that number.

public class PrimeNumber
{
Scanner scan = new Scanner(System.in);
int userNum;
String neg;

public void getUserNum()

[code]...

View Replies View Related

Long Type Output File - Print Prime Numbers Between Given Range Of Numbers

Aug 22, 2014

I tried to create file and write the output of my program in it in java when i use WriteLong then the file does not contain long value, how I create this file my program is to print prime numbers between 500000 to 10000000

public class primenumber {
public static void main(String[] args) {
long start = 5000000;
long end = 10000000;
System.out.println("List of prime numbers between " + start + " and " + end);
for (long i = start; i <= end; i++) {
if (isPrime(i)) {
System.out.println(i);

[Code] ....

View Replies View Related

Print 2 Lists - 20 Random Numbers And Another List Without Duplicate Numbers

Feb 1, 2015

I'm trying to make a program that generates 20 random integers between 1 and 20 and then prints the list of random numbers to the screen. After that, I want to print a different list to screen with the same numbers from the first list only skipping any number that has been already printed to the screen. So two lists are printed to the screen. The first one has 20 random numbers. The second one has those same 20 numbers but only prints the numbers in the first list that aren't duplicated. So if m

y list of 20 random integers contains three 2s and two 14s, only one 14 and one 2 is printed to the second list. Currently, my code generates 20 numbers from 1 to 20 and stores those numbers in an array but I don't know how to print solve the second part of my problem. I don't know how to print the s different list only without duplicate numbers. As a result, my output is nothing because it doesn't print any number from the first list as oppose to skipping only duplicate one.

public void randomNum(){
System.out.println("Twenty random integers: ");
int max = 20; // max value for range
int min = 1; // min value for range
Random rand = new Random();
int[] all = new int[20];

[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

Accept String And Number Of Repetitions As Parameters And Print String Given Number Of Times

Oct 3, 2014

I'm having a hard time with this problem, this is what I have, but I can not use two integers, I have to use one integer and a string...

This is the question:

Write a method called printStrings that accepts a String and a number of repetitions as parameters and prints that String the given number of times. For example, the call:

printStrings("abc", 5);

will print the following output: abcabcabcabcabc

This is what I attempted:

public class printStringsproject {
public static void printStrings(int abc, int number) {
for (int i = 1; i <= number; i++) {
System.out.print("abc");
}
}
public static void main(String[] args) {
printStrings(1, 5);
}
}

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

Print 10 Numbers Per Line

Feb 6, 2015

Am having trouble understanding how to print my results (I have 50 of them) , only 10 per line.

Im using an array that is 1-50. The first 25 I raise to the power of 2 and print it.

The next 25, I multiple by 3 and print it

Public class KDowling { 
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
double [] alpha = new double[50]; //declare an array 50 indexes
int num=1; // declare variable num
int counter=1;

[Code] .....

I need to get this result:

1 4 9 16 25 36 49 64 81 100
121 144 169 196 225 256 289 324 361 400
441 484 529 576 625 78 81 84 87 90
etc...

Right now they are each printing out on their own line.

View Replies View Related

Print Out Commas For Numbers

Oct 27, 2014

I've almost got this to work. Right now it prints out one comma for the first set of 3 numbers. For exmaple, if the user input is 12345678 the code will print out 12345,678. I'm trying to figure out how to get it to print out commas for the rest of the numbers. My first thought was to use a loop but I can't get it to work....

private static void printWithCommas(NaturalNumber n, SimpleWriter out) {
assert n != null : "Violation of: n1 is not null";
assert out != null : "Violation of: out is not null";
assert out.isOpen() : "Violation of: out.is_open";
if (n.compareTo(THOUSAND) < 0) {
out.print(n);

[Code] .....

View Replies View Related

Threads - Print Even And Odd Numbers Between 0 And 30

Mar 11, 2015

Here is what I am trying to do:

Write a program to print the even numbers and the odd numbers between 0 and 30 using a single thread and then again using multiple threads.

I already finished the single-threaded program but am having trouble with the multi-threaded one. I have three classes; one class for odd numbers, one for even numbers, and one to execute the code. Here is my code so far:

Even Numbers:

Java Code:

public class EvenNumbers extends Thread {
public void run() {
for (int i=1; i<=30; i++) {
if (i%2 == 0) {
System.out.println("Even number " + i);

[Code] ....

Unfortunately, my output ends up looking a little weird:

Java Code:

C:UsersREDACTEDDropboxSchoolworkREDACTEDJava ProgrammingUnit 5 - Exception
Handling, AssertionsProgram - Thread>java MultiThread
Even Numbers:
Odd Numbers:
Even number 2

[Code] .....

View Replies View Related

Add Up 4 Numbers And Print Out On Screen

Jan 20, 2014

I just started taking a Java class and i'm having problems with this code,

I'm trying to add up the 4 numbers have them print out on screen.

public class finalGrade
{
public static void main(String[] arg)
{
double pLp = 28.3; //Participation, lab work, and programming

[Code] .....

View Replies View Related

How To Print All Numbers Of Array In Java

Jan 1, 2015

This is my code

package com.arraydemo;
import java.util.TimeZone;
import java.util.concurrent.TimeUnit;
public class ArrayStructures {
public long[] theArray;
public int arraySize;
public ArrayStructures(int size)

[code]....

and i am getting this output

----------
! 1712 !2156|
----------
! 1713 !4583|
----------
! 1714 !3981|
----------

[HENRY: 6000+ LINES DELETED -- Isn't it a bit ridiculous hard to read when you flood a post with thousands of output lines?]

----------
! 4998 !3094|
----------
! 4999 !836|
----------
12:10:56

I am expecting Number to be print from Index ) but they are not printing ,why?

If I use arraysize like 2000 I am getting all number starting from 0 to 1999 .why?

View Replies View Related

How To Print Double With 2 Decimal Numbers

May 3, 2014

I am trying to cast an integer into a double. it works but I need two decimal number after the dot and for example I can print 7.51 but how can I get it to print 7.50 and not 7.5

public int compareTo(Money o){
int d1 = (this.dollars * 100) + this.cents;
int d2 = (o.dollars * 100) + o.cents;
return d1 - d2;
}

On my main method I have

public static void main(String[] args){
Money money1 = new Money(10, 49);
Money money2 = new Money(2, 99);
System.out.println("result: " + "$" + (double)money1.compareTo(money2)/100);
}

It prints 7.5 but I want it to print 7.50, how do I do this .....

View Replies View Related

Print Triangle Shape Using Numbers?

Jun 1, 2014

i want to print triangle shape using number like

this

1

12

123

1234

12345

123456

this is my code

class shape{
public static void main(String [] args){
for(int x =0 ; x<=6;x++){
for(int y =0 ; x > y ; y++){
System.out.print(x);
}
System.out.print("
");
}
}
}

but my output is

1

22

333

4444

55555

666666

View Replies View Related

How To Hold And Print Distinct Numbers

Sep 29, 2014

I am able to get the integer in the array printed but I am lost on how to hold and print the distinct numbers.

This program will read in 10 numbers from the user via the console. It will display on the console only the distinct numbers, i.e. if a number appears multiple times in the input it is displayed only once.

Here is a sample test run:
Enter an integer: 2
Enter an integer: 6
Enter an integer: 1
Enter an integer: 8
Enter an integer: 6
Enter an integer: 1
Enter an integer: 2
Enter an integer: 4
Enter an integer: 7
Enter an integer: 5
The number of distinct values is 7
2 6 1 8 4 7 5

View Replies View Related

Union Is Not Working Well - It Print Only The Numbers In Array X

Oct 9, 2014

import java.util.Scanner;
public class Arrayunion {
/**
* @param args

[Code].....

View Replies View Related

Print Only Top 15 Highest Numbers Of Occurrence From RNG Output

Oct 15, 2014

I created a random number generator for my course and it works perfectly. I now need to print only the top 15 highest numbers of occurrence from the RNG output. How i can do this?

Here is my block of code.

package section4;
import java.util.Random;
public class Lottery {
public static void main(String[] args) {
Random rand = new Random();
int freq[] = new int[51];

[Code] ....

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

Program Should Print Out Numbers For Each Vehicle Category

Aug 2, 2014

2.Check the Vehicle...Assume that vehicles are going through a two-way traffic intersection. There are three types of vehicles: car, motor bikes and trucks. Generate a series of 10 random integers, between 1 and 3, inclusive. The numbers represent the type of vehicle as stated below:

NumberVehicle Category
1 Car
2 Motor bikes
3 Trucks

Write a program, using a for loop, to count how many vehicles going through the traffic intersection are cars, motor bikes and trucks. Then, the program should print out the numbers for each vehicle category. There is no user input for this program.

View Replies View Related

Continue Statement - Print Out What Numbers Showing Up And How Many Times For Each

Mar 22, 2014

I read on how to use the continue statement, but I'm failing in how to use it properly, mostly because it's not working. I'm supposed to print out what numbers are showing up and how many times for each. Plus, I have to print out 'times' instead of 'time' if there's more than one of a certain number. Right now, it's printing out all the numbers including the ones that don't get inputted.

import java.util.Scanner;
public class occurrence {
public static void main(String[] args) {
 
//scanner/values
Scanner input = new Scanner(System.in);
int number = 101;

[Code] ....

View Replies View Related

Can't Print Number

Oct 14, 2014

I can't print the number that is supposed to come out

public class Skateboard {
private int wheels = 4;
private int trucks = 2;
private int bearings = 8;
private int gripTape = 1;
 
[code]....

How come sb1.assembly() doesn't return the values? :/

View Replies View Related

Swing/AWT/SWT :: Print Numbers Ten Per Line And Separate By Exactly One Space In Dialog Box?

Feb 17, 2014

The question is Write a program that displays all the numbers from 100 to 1000, ten per line, that are divisible by 5 and 6. and separated by exactly a space.

My assignment requirements are to display this in Dialog Box / message box . I have written this code so far

import javax.swing.JOptionPane;
public class Exercise04_10 {
public static void main(String[] args) {
int count = 1;
for (int i = 100; i <= 1000; i++)
if (i % 5 == 0 && i % 6 == 0)

How to display the output in dialog box?

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

Repetition - Print Number Of Occurrences

Apr 11, 2015

find whether it is a repetition free number or not. If it is, print the same number(x), else if it has repetitions then print the number of occurrences of the first repetitive digit you encounter.

View Replies View Related

Print 2 Largest Number In Array

Apr 1, 2014

Thought process : Sort the array and print the last 2 element of any given array.

Note /| Should not use any inbuilt Array.sort()

Java Code:

//Write a code to print the 2 largest numbers from the given Array {2,8,10,5,9}

package arrays;
public class biggest2numbers {
public static void main(String[] args) {
int[] A = {2,8,10,5,9};
//Declaring 2 variable
int Max1,
Max2;

[Code] .....

View Replies View Related







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