Programs To Display Only Odd Numbers Between 1 And 15

Nov 16, 2014

I have a programs to write which is to display only the odd numbers between 1 and 15 and the code i use it is not display what i was expecting it to but instead it looping 15 times and at the end it says that the odd number is 15 or 1. where or what have i entered wrong. it supposed to display only the odd numbers between 1 and 15here is the code that I write.

Scanner input = new Scanner (System.in);
int i, num=0, count = 0, count_odd = 0, oddnum = 0;
for(i=1; i<=15; i++) {
System.out.println("Please enter number");
num = input.nextInt();
}

[Code]....

View Replies


ADVERTISEMENT

Generate 100 Numbers Using Arrays - Sort Even Numbers Into Separate Array And Display Both

Apr 24, 2014

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

[Code] .....

View Replies View Related

Display Decimal Numbers Only

Jul 6, 2014

What code to use to display decimal numbers only. for example 125.50. the program will only display .50

View Replies View Related

Write Application That Display Numbers 1 To 4 On Same Line

Jul 22, 2007

I'm going to be taking an object oriented paradigm using java during intersession in a few months. I'm trying to brush up on it a bit. The problem is. Write an application that displays the numbers 1 to 4 on the same line, with each pair of adjacent numbers separated by one space. Write the program using the following techniques:Use one system.out.printLn statement.Use four system.out.print statement.Use one system.out.printf statement.

This is what i have so far .

Java Code: public class Display
{
public static void main(String [] args) {
System.out.print("1 ");
System.out.print("2 ");
System.out.print("3 ");
System.out.print("4 ");
System.out.println(" ");<----is that what that is supposed to look like, and where it goes?
System.out.printf(" %s %s %s %s ");????
}
} mh_sh_highlight_all('java');

i cant test this my console isn't working right, and i haven't finished my compiler install.

View Replies View Related

Display Largest And Smallest Numbers In A Series Of 10 Inputs

Apr 15, 2014

I have to get the user to enter in 10 numbers and with those 10 numbers I have to find the total, average, smallest, largest numbers in the set the user inputs. I have the total and average already figured out but how would you go about trying to find the largest and smallest numbers within this set of code.

import java.util.*;
public class testhw7
{
public static void main (String [] args) {
Scannernumberin = new Scanner (System.in);
doublevalue[];
doubletotal;

[Code]...

View Replies View Related

Display Two Numbers / Integer Code And Computed Result To Screen

Oct 26, 2014

Write a program that will read two numbers and an integer code from the keyboard. The value of the integer code should 1, 2, 3, 4. If the value of the code is 1, compute the sum of the two numbers. If the code is 2, compute the difference (first number minus second). If the code is 3, compute the product of the two numbers. If the code is 4, and the second number is zero, compute the quotient (first divided by second). If the code is not equal to 1,2,3,4, display an error message. The program is then to display two numbers, the integer code and the computed result to the screen

here is the code that I have so far:

public static void main(String[] args) {
Scanner read = new Scanner (System.in);
int num1, num2, code, sum;
System.out.println("Please enter a number");
num1 = read.nextInt();

[Code] .....

View Replies View Related

Use IDE When Writing Programs

Mar 27, 2014

I was wondering if you use an IDE when writing programs?Can you use J frame when using command line or is it just used with an IDE and do you go into framing in the book?I have taken programming classes and I am still stuck.

View Replies View Related

What Programs Use Abstract Classes

Sep 15, 2014

What programs use abstract classes?

View Replies View Related

Changing Values In Different Programs?

May 20, 2014

I'd like to make a simple cheat for an old game that's offline... It has no type of anti-cheat and I'd like to make a program that changes how much money you have... I think the first thing I have to do is get the data address or something like that by using cheat engine... How do I do that? After that how do I start using that info in my program and then send back a new value? Are there any classes that I should be importing and what methods do I use to do this?

View Replies View Related

Resize Window To See Programs

Jan 21, 2014

Whenever I make something in Swing, I always need to resize the window for me to see the graphics on the window. I have been told to use the pack() method on it, which I have, but the problem with it is that it just sets the window to a minimal size, only displaying the x + and -.For one of the "games" I made, it at first didn't work until resize, then I added a repaint() after the constructor and it worked for me, but when my friends download it they cannot see it.

View Replies View Related

Running Programs Through Java

Mar 30, 2014

I've been playing around with this for about an hour.

Java Code:

Runtime runTime = Runtime.getRuntime();
try {
Process process = runTime.exec("notepad");
} catch (IOException e) {
e.printStackTrace();
} mh_sh_highlight_all('java');
So that works. Notepad will open.

However, I'm trying to get other programs to open. Specifically, this program: C:Octave3.2.4_gcc-4.4.0inoctave-3.2.4.exe...However, using that in place of notepad doesn't work. I'm assuming that there is some sort of system variable that explains why simply typing "notepad" works? As if you type notepad into the run box, notepad will open. Soo does that snippet work by going through some sort of system variables?How would I go about opening other programs, such as the one I referenced above.

View Replies View Related

Program That Will Allow Programs Only At Certain Time

Sep 25, 2014

So I am making a program that will allow programs only at a certain time and i'm not sure how I would set the time for the program.

View Replies View Related

How To Structure Simple Java Programs

May 8, 2015

how to structure simple programs (i.e. one-method algorithms for a simple purpose). There are a few different ways that I have been doing it, but I want to be consistent. Should I put both the one-method algorithm (e.g. a factorial function) and the main method that executes the algorithm into the same class and then export it to an executable .jar file for use? Or should I create one class for the algorithm and another for the main method that executes the algorithm? In addition, is there any reason that I should out these classes in a package before I export it?

As another similar question, if I have constructed two distinct classes with two separate purposes, and they are both used in the construction of a single program, then would it be best to just put the main method in a third, separate class or should I put it in one of the two classes?

View Replies View Related

How To Compile And Run Java Programs Using JDK And JCreator

Jan 26, 2014

How do I set the class path, the path, compile and run java programs using jdk and jcreator?

View Replies View Related

Running Java Programs From Command Prompt

Dec 17, 2011

My PC runs on Windows XP. When I try to run a java program (written using NetBeans) from the command prompt, the program opens in NotePad but does not run.This is what I have been typing at the command prompt:

C:javahellosrchelloHello.java

The above is the correct path to the Java file on my PC.how to run the program from the command prompt or perhaps link me to a tutorial that explains it?

View Replies View Related

How To Get Data Button To Display User Inputted (numbers) To Data Label

May 25, 2014

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class DisplayFinal_Panel extends JPanel {
private JLabel label1, label2, label3;
private JTextField box;

[code]....

I only want Listener 1 to work right now. Also, user input is in TextField.

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

User To Enter 10 Numbers And At The End Prints Out Distinct And Non-repeated Numbers

Nov 23, 2014

I have to make a program that prompts the user to enter 10 numbers and at the end it prints out the distinct numbers and then the other numbers that weren't repeated...

I have the part where it prints out the distinct numbers but I stuck on how to make it print out the other numbers that didn't repeat...

import javax.swing.JOptionPane;
public class DistinctNumbers {
public static void main(String[] args) { 
String getInput;
int input;
int[] numbers = new int[10];

[Code] ....

View Replies View Related

Display Some Messages On Output File In Display Head Function

Mar 18, 2014

Write a class named FileDisplay with the following methods:

1.) constructor: the class's constructor should take the name of a fil as an arugment.
2.) displayHead: This method should display only the first five lines of the file's contents

Here is the following code I have made so far

import java.io.*;
public class FileDisplay
{
private String filename;
 public FileDisplay(String Filename) throws IOException

[Code] ....

First, in my constructor I have taken in an argument and used that argument to open up an output file. Meanwhile, I'm trying to work n the displayhead method to print out information and to read data to. I haven't opened up my input file yet, but I'm not understand how can I read a print data to an output file. in

public void displayHead()
{FileWriter file=new FileWriter(Filename)}

do I make create another instance of the filewriter class to output data?

In simple words, suppose to I want to display some messages on my output file in the displayhead function. Since I already have opened up the file in the constructor, how do I combine that in this method...

View Replies View Related

Generate Two Arrays - One With All Positive Numbers And Another With Negative Numbers

Mar 10, 2015

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

View Replies View Related

Generate Random Numbers Without Certain Numbers In Range

Jul 31, 2014

I tried out doing number (generated randomly) != (another number) but that does not work. If I for example want a number between 1 and 10, but I do not want the number 5, what can I do in order to make this happen?

View Replies View Related

List All Prime Numbers Between Two Entered Numbers

Oct 17, 2014

Program is to list all prime numbers between two entered numbers.

import java.util.Scanner;
public class question6 {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.println("Enter lower int:");
int x = input.nextInt();

[Code] .....

View Replies View Related

JSP :: Display XML - Catch Is To Display Each Tag With Different Colors

Nov 19, 2014

I am developing a product where the client needs to display the content of XML in a JSP page. This XML will be extracted from database and will be temporarily sotred in a String object and will then be flushed to JSP page for display. This was working fine unitl now. But now the customer wants display each tag with one color. attribute in another color and data in another color.

For ex: <?xml version="1.0" encoding="UTF-8"?>

this should be displayed in one color. Then

<ichicsrmessageheader>Data</ichicsrmessageheader>

In the above one the tag should be displayed in one color and "Data" should be displayed in another color

<organisation operationtype="1">Data</organisation>

In the above sample tag should be in one color and attribute should be in one color ex: red and value of the attribute should be in another color ex: blue and "Data" should be in one color ex: green.

Here is the sample screen shot of how xml should is currently being displayed.

View Replies View Related

Sum Of First N Numbers

Jul 1, 2014

I wrote a program to find the sum of first 10 numbers using the for loop... here is the piece of code

public class Sum {
public static void main(String[] args) {
int sum = 0;
for (int N=0; N<= 10; N++) {
sum = sum + N;
}
System.out.print("The sum of first 20 numbers is " + sum);
}
}

I tried to write the same program using the while loop but with no success. How can i write this using while loop?

View Replies View Related

ID Numbers Are All 0

Jun 4, 2014

I don't know what I did to screw this up, but I had this code working to increment each employee ID by one every time a new employee was added. I tried to move the whole employeeID and newEmployeeID elements out of the constructor because everyone keeps telling me how bad it is to have those in the constructor. However, now, every time I add an employee, their ID number turns out to be 0. I have two other aspects of this project that are due soon, and if I can't fix this part, I won't be able to move forward to the other parts (which I am also stuck on at this point). The codes that are being used are as follows:

import java.io.*;
import java.util.*;
import java.nio.file.*;
import java.text.NumberFormat;
public class Employee
{
// instance variables
private String firstName;
private String lastName;
private int employeeID;
static int newEmployeeID = 0;

[Code] ....

View Replies View Related







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