Write A Java Program To Input 7 Integers?

Feb 21, 2015

Design, write a java program to input 7 integers and, for each integer, calculate and display its square and cube.

View Replies


ADVERTISEMENT

Write A Java Program That Reads 5 Integers

Oct 9, 2014

Project is due before midnight eastern time (3 more hours). I have been working on this all day, we have not learned arrays or anything and just started 'for' loops. I don't really know how to implement that system yet. However, he wants us to check all the possible handwritten math ways of doing this. I have tried but I cannot return my numbers beside the card.my program only prints the type and I still have more cases to add as well..

QUESTION: Write a Java program that reads 5 integers, each of which is in the range of 1 and 13 representing a simplified poker card with no suit. Your program should then print the ranking of the hand with card number(s) beside the ranking. The rankings to determine are Four of a Kind(4 of the 5 cards of the same rank), Full House(3 of the 5 cards of the same rank, and 2 cards of another rank), Straight(5 cards of sequential rank), Three of a Kind(only 3 cards of the same rank), Two Pair(2 cards of the same rank, 2 cards of another rank, and no card of either rank), One Pair(only 2 of 5 cards are of the same rank), and High Card(no two cards of the same rank). Some sample runs are:

input: 2, 3, 2, 2, 2; output: Four of a Kind(2)
input: 2, 3, 2, 3, 2; output: Full House(2, 3)
input: 2, 3, 4, 5, 1; output: Straight(5)
input: 1, 13, 11, 10, 12; output: Straight(1)

[code]....

View Replies View Related

Write A Java Program That Reads A Positive / Non-zero Integer As Input

Aug 1, 2011

Write a Java program that reads a positive, non-zero integer as input and checks if the integer is deficient, perfect, or abundant.

A positive, non-zero integer, N, is said to be perfect if the sum of its positive proper divisors (i.e., the positive integers, other than N itself, that divide N exactly) is equal to the number itself. If this sum is less than N, the number is said to be deficient. If the sum is greater than N, the number is said to be abundant.For example, the number 6 is perfect, since 6 = 1 + 2 + 3, the number 8 is deficient, since 8 > 1 + 2 + 4, while the number 12 is abundant, since 12 < 1 + 2 + 3 + 4 + 6.

SAMPLE OUTPUT:

1.)Input N: 5

5 is deficient.

2.)Input N: 6

6 is perfect.

3.)Input N: 18

18 is abundant.

View Replies View Related

Write A Java Program Which Display To Get GPA Of A Student As Keyboard Input

Feb 15, 2015

I want to write a java program which displays to get the GPA of a student as a keyboard input. Then display the class of the degree according to the following criteria using a switch-case statement (if-else statements cannot be used). If the user insert an invalid gpa you should display a message Invalid GPA.

gpa ≥ 3.50 First Class Hons
3.49 ≥ gpa ≥ 3.00 Upper Second Class Hons
2.99 ≥ gpa ≥ 2.50 Lower Second Class Hons
2.49 ≥ gpa ≥ 2.00 Pass
2.00 ≥ gpa Fail

Here is my code:

import java.io.*;
public class q7
{
public static void main(String[] args)
{
InputStreamReader ISR=new InputStreamReader(System.in);
BufferedReader BR=new BufferedReader(ISR);
 
[code]...

.But when I use Command console to run this it says: 1111.jpg. I also wanna know is there another way to do this with switch- case statements.

View Replies View Related

Write A JAVA Program That Will Input 10 Scores And Output Highest And Lowest Score

Jan 9, 2015

1.Write a JAVA program that will input 10 scores and output the Highest and Lowest score.

2.Write a JAVA program that will input the base and power and display the result: Example: Base is 4 Power is 2 the answer is 16 (Note: Math.pow( ) method is not allowed)

3.Write a JAVA program that will input an integer number, and then will output the sum of all inputted numbers. The program will stop in accepting inputs if the user entered 0.

View Replies View Related

Write A Program That Reverses A List Of 15 Integers Preferably In Place

Nov 24, 2014

Write a program that reverses a list of 15 integers preferably in place.

View Replies View Related

Write A Program That Prompts User To Enter Two Positive Integers And Prints Their Sum

Jan 9, 2015

Write a program (TwoIntegers.java) that prompts the user to enter two positive integers and prints their sum (by addition), product (by multiplication), difference (by subtraction), quotient (by division), and remainder (by modulation). When the user enters 5 and 3, the output from your program should look exactly like the following:

Enter two positive integers: 5 3
The sum is 8.
The product is 15.
The difference is 2.
The quotient is 1.
The remainder is 2.

import java.util.Scanner;
public class TwoIntegers {
public static void main(String[] args) {
System.out.println("Enter two positive integers: ");
Scanner userInput = new Scanner("System.in");
int integer1 = userInput.nextInt();
int integer2 = userInput.nextInt();

[code]....

View Replies View Related

Allow User To Input One Or More Integers And Store Them In Vector For Manipulation Later On In Program

Oct 1, 2014

I'm playing with vectors for the first time... What I'm trying to do is to allow a user to input one or more integers and store them in a vector for manipulation later on in the program... Here's the portion of the program I'm working with:

Java Code:

package com.itse2317;
import java.util.*;
public class VectorTest
{
public static void main(String[] args)
{
Scanner input = new Scanner(System.in);

[code]...

My question is this: Is there any way to move from inputting integers to printing them, without entering a non-integer (for example, hitting enter)? I looked at the API for the Vector class, and either I'm not thinking about the problem the right way to be able to find an answer, or it's just not there.

View Replies View Related

Write A Program That Reads From User Several Lines Of Input

Mar 24, 2014

a. Assume that we have a list of employees' names of a company and their ages. Write a program that reads from the user several lines of input. Each line includes an employee's name and his/her age (as an integer). The program should calculate and print the following:

- The average age of all employees (rounded to 2 decimal places).
- The oldest employee and his/her age.

Hints:

You could assume that the user will insert valid data and at least one employee.
You could assume that the oldest employee is only one person.
User could stop the program via entering the word "end" as an employee's name.

Sample Input and Output: In each line, insert an employee's name and his/her age To halt the program, insert "end" as an employee's name

Adam 30
Tom 41
Ted 45
Karl 30
end

The average age of all employees is 36.50.The oldest employee is Hisham whose age is 45

View Replies View Related

Write A Program That Asks Users To Input 5 Test Scores

Apr 22, 2015

Write a program that asks the user to enter five test scores. The program should display a letter grade for each score and the average test score. Write the following methods in the program:

calculateAverage This method should accept five test scores as arguments and return the average of the scores. determineGrade This method should accept a test score as an argument and return a letter grade for the score, based on the following grading scale

Score Letter Grade
90-100 A
80-89 B
70-79 C
60-69 D
Below 60 F

double test1,test2,test3,test4,test5;
double average;
char grade;

Scanner keyboard = new Scanner(System.in);

System.out.println("Enter the first score");
test1 = keyboard.nextDouble();
System.out.println("Enter the second score");
test2 = keyboard.nextDouble();

[code]....

View Replies View Related

Program Prompt For Input File / Take Its Info And Write To Report - Nullpointer Exception

Apr 17, 2014

I've got a nasty nullpointer that I have tried to resolve to no avail as of yet. The program should prompt for a listings.txt file and take its info and write to a report file. Here's the stacktrace:

run:

Input file: listings
Exception in thread "main" java.lang.NullPointerException
at java.io.Writer.<init>(Writer.java:88)
at java.io.PrintWriter.<init>(PrintWriter.java:113)
at java.io.PrintWriter.<init>(PrintWriter.java:100)
at kettask2b.PropertyListingsReport.main(PropertyListingsReport.java:34)
Java Result: 1

Some adjustments that I have attempted are:

BufferedWriter pwfo = null;
for (int i = 0; i < args.length; i++) {
String string = args[i];
pwfo = null;

[Code] ....

Here's the code:

package kettask2b;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;

[Code] ....

View Replies View Related

Write Application That Reads Five Integers

Jun 12, 2014

Write an application that reads five integers, determines and prints the largest and smallest integers in the group. Use only the programming techniques you learned in this chapter. (which means: use only if statements and the equality and relational operators).If I want to solve this I will write nested if statements for every probability like the following.The probability: the first integer is the largest and the fifth integer is the smallest:

1>2>3>4>5
1>2>4>3>5
1>4>3>2>5
1>4>2>3>5
1>3>4>2>5
1>3>2>4>5

And so on for every probability.

View Replies View Related

Write A Java Program That Uses A While Loop

Apr 9, 2014

Write a java program that uses a While loop and persistent output to count down from 33 to 0 by threes, and put each value on a separate line, also do this in for loop.

View Replies View Related

Create And Write To A Excel File From A Java Program?

Jul 10, 2007

I want to create and write to a excel file from a java program. I found a tutorial online and wrote a java file as under:

Java Code: import java.io.File;
import java.util.Date;
import jxl.*;
import jxl.write.*;
public class jExcel{
WriteableWorkbok workbook = Workbok.createWorkbook(new File("output.xls"));
public static void main(String args[]){
WriteableSheet sheet = workbook.createSheet("First Sheett",0);
Label label = new Label(0,2,"A label record");
sheet.addCell(label);

[code].....

But when I compile this file, I get errors telling that package jxl does not exists and so on. Do I need to download it ?

View Replies View Related

Write A Java Program To Read Time Intervals

Feb 23, 2015

Write a java program to read the time intervals (HH:MM) and to compare system time if the system time between your time intervals print correct time and exit else try again to repeat the same thing. By using StringToknizer class.

View Replies View Related

Write A Java Program To Fill Excel Spreadsheet

Jul 15, 2014

I have an excel spreadsheet, with a specific filename and location which doesn't change (e.g. C:/workbook.xls)What I would like to do is have a window open when I open an .exe file, and in this window is a bunch of check boxes, text areas and drop down boxes (I can implement these, that's about my level of JAVA)

Then, when I click on a button in this window (for example, a button which says "Save"), the data from all these boxes and menus etc. goes into specific cells in the excel spreadsheet. Or if certain values are selected from a drop down menu, then a bunch of cells are empty.

View Replies View Related

Write A Program That Use Java String Class Methods

Feb 10, 2015

There are two versions

1. The words remain in their places but the letters are reversed. Eg I love you becomes Ievol uoy
2. The words are also reversed. Eg I love you becomes uoy evol IWrite a program that use the java String class methods.

View Replies View Related

Write Java Program That Asks User For List Of Names?

May 21, 2015

I am trying to write a java program that asks the user for a list of names (one per line) until the user enters a blank line. At that point the program should print out the list of names entered, where each name is listed only once (i.e., uniquely) no matter how many times the user entered the name in the program. I am supposed to use an ArrayList for this problem.

My idea for a solution is to create an ArrayList<String>, read each name, i.e., line, entered and then to see if that name is already in the ArrayList. I created a for loop to check each element in the ArrayList but when I try to assign an element to a string variable I get the error "Type mismatch: cannot convert from Object to String". Not sure why that is happening because the ArrayList is defined as a String list.

Here is the code so far.

/*
* File: UniqueNames.java
*/
import acm.program.*;
import java.util.*;

[Code].....

View Replies View Related

How To Write JAVA Program That Read Whole Number And Tell Decimal Place

Oct 10, 2014

Ex. If I type 5943, the program will say
mill = 5
hun = 9
ten = 4
uni = 3

get the picture I had to translate the decimal value names from a different language.

This is what I have tried...,

Java Code:

import java.util.Scanner;//Permite el uso de leer el teclado del usuario
public class DeterminarValorDecimal//Nombra el documento
{
public static void main(String [] args)//Podemos ver la clase
{

[Code].....

But what this does is I have to enter the single digits one by one. I want to be able to type the whole number. Is there a method that reads the length of the whole number and lets me classify each digit so I can do what I want to do?

View Replies View Related

Write Program For Diamond Shape In JAVA For Given Sample Pattern?

Oct 5, 2014

My son want to create a java program (Diamond shape) that can plot graph for with the following data.

Pattern type is:

* *

* *

*

* *

* *

*

View Replies View Related

Write Java Program That Calculates Area And Volume Of Cube?

Sep 10, 2014

Write a Java program that calculates the area and volume of a cube, sphere, cylinder, and regular tetrahedron. Your program should obtain the necessary input for each of the objects from the console and output the input, area, and volume of the object. Use appropriate messages to guide the user of your program.

Here what i did, i am not sure if this is what the assignment want, but this is the best method i could come up with

//Khang Le
import java.util.Scanner;
public class InputAreaVolume {
public static void main(String[] args) {

[Code]......

View Replies View Related

Write A Java Program To Store Employee Information In A Linked List

May 12, 2015

Write a java program to store employee information in a linked list, the program should implement the following functions:

The program should display the list of functions, and ask the user to enter the number of function that he/she wants to do, then perform the function as it is required in the previous table.

import java.util.*;
public class Employee {
Scanner in = new Scanner(System.in);
String Name;
String Address;
String Department;
int ID;
int Salary;

[code]....

this is my out put

Please choose a number:
1-Add a new employee
2-Update employee's info
3-Remove employee's info
4-Exit
1
Enter name:
Enter address:
2
Enter department:
3
Enter ID:
4
Enter salary:

now:

1- why are not my adding coming out in the output only the Enter name & Enter address ??

2- how can I add names and ID's and information to test that program

View Replies View Related

How To Take User Input As Integers

Jun 2, 2009

Suppose I write a program to multiply two numbers.

The user enters the numbers as follows:

2
3

How do I extract these integers inside main? [Explain the case where the integers are on two separate lines].

What to do for the newline inbetween?

View Replies View Related

Identifying Difference Between Integers And Words From User Input

Feb 24, 2015

I am currently taking a computer science class in high school, and its my first time programming (2 weeks since i started). I have currently finished my program however there were a few details that bothered me. I was supposed to create a program which can calculate average of individual marks and then calculate all of the average marks previously entered by user. However I noticed something that bothered me, which was the fact that if i were to enter a number when asked to enter a name, it would assume that number is a name. Also when I asked for the 5 marks the program would run fine until an error occurs if i accidentally type in a letter or word. I have done some research and found system scanners however i still don't understand the concept in a looping situation. Here is what I have so far.

import java.io.*;
public class loopingEx6Final {
public static void main(String args[]) throws IOException{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
double average, totalaverage = 0;
int Mark, Marktotal=0, marktotalsum=0, count=0;

[Code] .....

View Replies View Related

Print Maximum And Minimum Values Of Integers From User Input

Apr 27, 2015

So I'm learning java from a website and I was tasked with creating a simple program which allows the user to enter a series of integers, then finally when they decide to input a non-integer the program will print the maximum and minimum values of the integers they entered. So for example if they entered 5, 4, 3 and 2 then enter a non-integer the program would output 5 (maximum value), then 2 on a new line (minimum value).

Here is my code:

import java.util.Scanner;
public class MaxMinPrinter {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int max = Integer.MIN_VALUE;
int min = Integer.MAX_VALUE;

[Code] ....

And this is what the output looks like:

Actual output
-------------------------------------------
Enter an integer: 5
- 10
-
- Enter an integer: -4
- 8
- -6
-
- Enter an integer: 11
- -1
-
- Enter an integer: q
- -1
- -6

When it's supposed to look like this:

Expected output
-------------------------------------------
Enter an integer: 5
Enter an integer: 10
Enter an integer: -4
Enter an integer: 8
Enter an integer: -6
Enter an integer: 11
Enter an integer: -1
Enter an integer: q
11
-6

View Replies View Related

CountDigitx - Take Two Integers As Input And Return How Many Time X Occurs In Number N

Apr 29, 2014

Write a recursive Java method countDigitx that takes two integer numbers as input (a number n and digit x) and returns the number of times digits x occurs in number n:

For example if n=23242 and x=2 then the method should return 3 that is the number of times the number 2 found in n.

View Replies View Related







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