Program Ask For Five Names Using Loop Statement And Print All
Jan 24, 2014write a program that would ask for the five names using loop statement and print all names .
View Replieswrite a program that would ask for the five names using loop statement and print all names .
View RepliesAlright so I'm trying to write a code that implements a for loop and if statements that displays any number from 100-200 if the number is divisible by either 5 or 6 in rows of ten numbers each row. If it is not divisible by that number then it should go back to the beginning of the loop until it reaches 200. My main problem is that it doesn't display anything. I don't get any errors or anything but every time I run the program it just displays nothing. Sample output is at the bottom of the code.
public class Exercise5_11 {
public static void main(String[] args) {
int count = 0;
int i = 100;
//for (the numbers from 100 to 200)
for (i = 100; i>100 && i<200; i++){
[Code] ....
/*Output
100 102 105 108 110 114 115 125 126 130
132 135 138 140 144 145 155 156 160 162
165 168 170 174 175 185 186 190 192 195
198 200
*/
It is still wip of course so I was trying to just get it to display int i but it doesn't do anything and I'm not really sure why.
Write an application, HiFour that prompt for four names and then prints the greetings, but with the names in reverse order and with punctuation as shown in the example.
Enter four names: Alice Bob Carol Dave
Hi Dave, Carol, Bob, Alice.
I just started in java programming and into Arrays multidimensional. I started a simple 2 dimensional array with 5 names with genders. I 'm having issues because it does not want to print out the names with correct genders Male/ Female. The simple program should print out the 5 names with gender type.
example:
Jack - Male
Sally - Female
Dave - Male
Sue - Female
Brian - Male
Here is what I came up with so far:
public class Multiname
{
public static void main(String[] args)
{
//String[][] multiname;
String [][] multiname =
[Code] .....
This is the result:
multiname : Jack
multiname : sally
multiname : Dave
multiname : Brian
multiname : Sue
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 1
at MultiD.main(MultiD.java:29)
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.
I'm trying to write a program to read the names off of email addresses in a text file and my code is not printing anything to the console. So I want to print everything before the "@" sign. It seems like I'm missing a big thing
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.Scanner;
public class Email {
public static void main(String[] args) throws FileNotFoundException, IOException {
[Code] ....
Implement a Las Vegas slot machine! The machine works as follows. First, it generates three random integers (use import java.lang.Math.*; then call Math.random()*7 to generate a random number between [a,b)) that are in the range of 0-7. Once the numbers are generated, the following rules are used to determine the prize:
- If all three numbers are equal to 7, you are winning $1,000,
- If all three numbers are equal, but not equal to 7, you are winning $500,
- If two of the numbers are equal to 7 and the third one is six, you are winning $400,
- If two numbers are equal, you are winning $100,
- Otherwise you are not winning anything.
And for that I wrote:
import java.lang.Math;
public class Assn1_2150130 {
public static void main(String[] args) {
// Generate three random signle-digit integar from 0-7.
int n1 = (int)(Math.random()*7);
int n2 = (int)(Math.random()*7);
int n3 = (int)(Math.random()*7);
[code]...
But I just can't figure out a way to print out the "YOU WON NOTHING." independently.If I say that n1!=n2 && n2!=n3 && n3!=n1, and then write another line of println. It gives out the number as well as the "NOTHING".
This code is supposed to convert a decimal base number to base 2, 8 or 16. It prints the number but it's supposed to be in the reverse order for example when converting 188 to base 16. it prints CB instead of BC.
package test;
import java.util.Scanner;
public class Test {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.println("Enter a positive integer.");
int number = input.nextInt();
[Code] ....
I'm trying to make a statement of elapsed time print out after I've executed everything with a ThreadPoolExecutor. What happens is that instead of printing out after all the iterations within the for each loop are done, it prints out the elapsed statement in the middle of the iterations or even in the beginning of the whole execute() method. Here is my code:
package com.atem;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadPoolExecutor;
public final class Example {
[Code]...
I've done a basic login GUI for a application, a user enters their name and address and clicks register, a four digit pin is then randomly generated, the pin and name and address are all added to an object of the MemberDetails class , this obj is then added to an array list.
returning customers can then enter a previously generated pin and either get a welcome back message or an invalid pin message.
my issue if i register two new users and get their generated pins, that on the returning members screen it will only show the welcome message for the second new customer i created and not recognizing the first customers pin. heres my code:
taking in new customer details, generating pin , adding obj to arraylist
int randomPIN = (int) (Math.random() * 9000) + 1000;
members = new MemberDetails();
members.name = nameNew.getText();
members.address = addressNew.getText();
members.pin = randomPIN;
[Code] ....
that lest method is a bit of a mess i know, i was going to store the log in attempts in a array but thats probly not a good tactic, and that inner for loop is probly unnecessary ?
I am having trouble doing a simple exercise changing a for loop to a while statement, it works fine in the for loop but in the while statement it just prints out 10(it is supposed to count to 0 and print liftoff).
public void run() {
int i = 10;
while (i>=1) {
println(+i+"...");
i--;
}
println("liftoff...");
}
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] ....
I am having a problem with looping a while loop that contains a switch statement. Here is my code:
package hw4jenningsd;
import javax.swing.*;
public class HW4JenningsD {
[Code].....
I am trying to add a while loop into my switch statement. If you run the program, it will ask to enter the class grade (9,10,11, or 12). If you insert 5, it will say to try again. But, if you enter a wrong number twice, it will continue on to the next part of the program, which is asking how many students are in the class. Therefore, I believe a while loop would work, but it is not working at all. The program still runs, just doesn't fix the error. The program is below:
import java.util.Scanner;
public class stephProject {
public static void main(String[] args) {
//call method
welcomeMessage(); //method 1 of 3
[Code] ....
Here is my code so far. I am trying to get the WHILE LOOP to work so the user inputs a number, the if statement prints the output and then it returns to ask for another number and goes again and again looping :
import java.util.Scanner;
public class ifwhileloop {
static Scanner sc = new Scanner(System.in);
public static void main(String[] args) {
double nmbr;
[Code] ....
I made this calculator in C++ and it worked wonderful so I decided to make it in java. When I run the program it gives me no errors but my if statements inside my while loop don't work
import java.util.Scanner;
public class ohmlaw {
public static void main(String args[]) {
float current;
float resistance;
float voltage;
String calchoice = new String();
Scanner cc = new Scanner(System.in);
[code]....
cannot break from while loop. Whenever I am trying to exit from startCustomerManagement-> backEnd() -> mainScreen()..It gets stuck between mainScreen and backEnd screen. However I can exit from backEnd()->startCustomerManagement() screen
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package javaapplication19;
import java.io.BufferedReader;
[code]...
I have wrote the necessary program for the class which was : Modify the customer class to include changeStreet(), changeState(), and changeZip methods. Modify the account class to include a changeAddress() method that has street city and zip parameters. Modify the Bank application to test the changeAddress method.
The problem arose when I went to test it. For some reason when it asks "Would you like to modify your account information? (y/n)" it will not allow the user to input anything and thus test the class. Here is my code
Class Customer
import java.util.*;
import java.io.*;
public class Customer {
private String firstName, lastName, street, city,state, zip;
[Code] ....
I have to take user input and then count how many times each number that the user input and print each one out. For some reason, I can't even get the for loop statement to print and it's pretty much the same as my other program except for the loop which is a little different.
//User inputs numbers between 1 and 100, program counts how many of each integer is and ends with a 0
import java.util.Scanner;
public class occurrence {
public static void main(String[] args) {
//scanner/values
Scanner input = new Scanner(System.in);
int number = 0;
int c = 0; //array count
[Code] ....
I'm trying to create a switch statement inside of a counter controlled (while) loop that asks for an input of...
"How many characters would you like to convert?"
Then you type in a number > 0, and then it should convert letters into the "1337" equivalent.
This is an example on what it should do.
How many characters would you like to convert? 5
Enter character #1 to convert: !
!-
Enter character #2 to convert: $
$-
Enter character #3 to convert: #
#-
Enter character #4 to convert: *
*-
Enter character #5 to convert: ,
, -
Whenever i try to run the program, i only get the- How many characters would you like to convert- i input 5 but then nothing else prints..
My codes..
System.out.print ( "How many characters would you like to convert?: " );
int convertCounter = 1;
char ch;
ch = input.next().charAt(0);
while (convertCounter > 0)
switch ( ch ){
[Code] ....
I need to make a program that keeps track of peoples names, allows you to add a note to each name and preferably would reorganize whatever you put in by date or by spelling. (I suppose the phonebook application in cell phones is a good match, a supermarket's list of foods and prices would work as well).
View Replies View RelatedI want an app that I can use to save the name, address, item sold, subject discussed and date that I visited someone - in a job similar to a sales rep. I would like to be able to choose how to sort the info so that if I sort by date I can see who hasn't been visited for the longest and start there. If I think of someone's name then of course I want to sort by name.
One of my friends says he works with "php"[? I'm still learning these terms] and everything happens online. I would like it to be an android app so it can be done without an internet connection ....
I am trying to execute the following method: This method takes a delivery date as one of the arguments and a list of calendar holidays as another argument. If the delivery date is present in the holiday list, I will add 1 day more to the delivery date and check again if the new delivery date is part of holiday list.
Issue is that the last 3 statements before 'return' are getting executed multiple times though there is no for or while loop. Why they are getting invoked multiple times.
@SuppressWarnings("rawtypes")
private String fetchNextWorkingDay(String sDeliveryDate, Element eleCalendarDayExceptions, SimpleDateFormat sdf, Format formatter) throws Exception {
System.out.println("");
System.out.println("Inside fetchNextWorkingDay method");
System.out.println("Del Date to compare is "+sDeliveryDate);
Boolean isDateSet = true;
[Code] .....
write a program to sort names according to number of vowels sort({sam,ratan,alok,raj}) the op is {sam,ratan,alok,raj}
View Replies View RelatedAlright so I wrote a switch statement that decides what range to print based on the letter grade input.
import java.util.Scanner;
public class SwitchPractice
{
public static void main(String [] args)
{
Scanner scan = new Scanner(System.in);
[code]...
It works fine, but once it the user enters a letter grade and then displays the value, it does not prompt the user for another letter grade so that it can perform the output again. Also if I wanted to display an error message to the user if they enter an invalid letter grade how would I do that. I tried using a while loop and if statement in the switch statement but that didn't work.
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].....