I really need help with this. Your tips are greatly appreciated: - import java.util.Scanner;
-
-
public class PhoneNumbers
-
{
-
public static void main(String[] args){
-
Scanner input;
-
-
Scanner scan = new Scanner(System.in);//get user input
-
-
System.out.print( "Please enter a phone number:");
-
-
String word = scan.nextLine();
-
int numOfDigits = word.length();
-
boolean hasMoreDigits = false;
-
boolean hasLessDigits = false;
-
-
if(numOfDigits > 5){
-
for (int i = 0; i < numOfDigits; ++i){
-
if (numOfDigits < 10){
-
hasLessDigits = true;
-
}
-
else if (numOfDigits > 10){
-
hasMoreDigits = true;
-
}
-
-
if (hasLessDigits && hasMoreDigits){
-
break; // check finished
-
}
-
}
-
-
if (hasMoreDigits){
-
System.out.println
-
("Your phone number has more than 10 digits!");
-
}
-
else if (hasLessDigits){
-
System.out.println("Your phone number has less than 10 digits!");
-
}
-
else{
-
System.out.println("Your phone number is 10 digits!");
-
-
}
-
}
-
}
-
public static String reFormat (String word)
-
{
-
word = String.format("({0}) {1}-{2}",
-
word.Substring(0, 3),
-
word.Substring(3, 3),
-
word.Substring(6));
-
-
}}
3 23796
I really need help with this. Your tips are greatly appreciated: - import java.util.Scanner;
-
-
public class PhoneNumbers
-
{
-
public static void main(String[] args){
-
Scanner input;
-
-
Scanner scan = new Scanner(System.in);//get user input
-
-
System.out.print( "Please enter a phone number:");
-
-
String word = scan.nextLine();
-
int numOfDigits = word.length();
-
boolean hasMoreDigits = false;
-
boolean hasLessDigits = false;
-
-
if(numOfDigits > 5){
-
for (int i = 0; i < numOfDigits; ++i){
-
if (numOfDigits < 10){
-
hasLessDigits = true;
-
}
-
else if (numOfDigits > 10){
-
hasMoreDigits = true;
-
}
-
-
if (hasLessDigits && hasMoreDigits){
-
break; // check finished
-
}
-
}
-
-
if (hasMoreDigits){
-
System.out.println
-
("Your phone number has more than 10 digits!");
-
}
-
else if (hasLessDigits){
-
System.out.println("Your phone number has less than 10 digits!");
-
}
-
else{
-
System.out.println("Your phone number is 10 digits!");
-
-
}
-
}
-
}
-
public static String reFormat (String word)
-
{
-
word = String.format("({0}) {1}-{2}",
-
word.Substring(0, 3),
-
word.Substring(3, 3),
-
word.Substring(6));
-
-
}}
Try to have some experiments on the code below... - System.out.printf("%s %d %.2f %.5f %c", "I love java",10, 1.2034, 1.1, 'z');
And try it to use String.format() instead of using System.out.prin tf...
Update us,
sukatoa
I really need help with this. Your tips are greatly appreciated: - import java.util.Scanner;
-
-
public class PhoneNumbers
-
{
-
public static void main(String[] args){
-
Scanner input;
-
-
Scanner scan = new Scanner(System.in);//get user input
-
-
System.out.print( "Please enter a phone number:");
-
-
String word = scan.nextLine();
-
int numOfDigits = word.length();
-
boolean hasMoreDigits = false;
-
boolean hasLessDigits = false;
-
-
if(numOfDigits > 5){
-
for (int i = 0; i < numOfDigits; ++i){
-
if (numOfDigits < 10){
-
hasLessDigits = true;
-
}
-
else if (numOfDigits > 10){
-
hasMoreDigits = true;
-
}
-
-
if (hasLessDigits && hasMoreDigits){
-
break; // check finished
-
}
-
}
-
-
if (hasMoreDigits){
-
System.out.println
-
("Your phone number has more than 10 digits!");
-
}
-
else if (hasLessDigits){
-
System.out.println("Your phone number has less than 10 digits!");
-
}
-
else{
-
System.out.println("Your phone number is 10 digits!");
-
-
}
-
}
-
}
-
public static String reFormat (String word)
-
{
-
word = String.format("({0}) {1}-{2}",
-
word.Substring(0, 3),
-
word.Substring(3, 3),
-
word.Substring(6));
-
-
}}
HI...you can try the following code format to solve your problem.....
-------------------------------------------------------------------------------------------------
Again: please don't feed boiler plate solution code; the OP won't learn anything
from copying/pasing code from somebody else. Read the forum guidelines about
this very matter (see the 'Help' link near the top right of this page). If you continue
posting code like this you risk a ban from this forum site. Don't do it anymore.
kind regards,
Jos (moderator)
HI...you can try the following code format to solve your problem.....
-------------------------------------------------------------------------------------------------
Again: please don't feed boiler plate solution code; the OP won't learn anything
from copying/pasing code from somebody else. Read the forum guidelines about
this very matter (see the 'Help' link near the top right of this page). If you continue
posting code like this you risk a ban from this forum site. Don't do it anymore.
kind regards,
Jos (moderator)
hi...i just wanted to describe how code will be optimize...i didn't do spoon feeding...i was trying to describe what should be our approach to sovle the problem...the person who has raised the request was doing many extra things in his...so i wrote that code....after all if u seem i have made a wrong thing then sorry for that.....thaks
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: deko |
last post by:
The below code dials a phone number using C:\Program Files\Windows
NT\dialer.exe. The problem is that dialing rules are ignored. MS Knowledge
Base Article 266253 suggests that entering the phone numbers in canonical
format, e.g. +011 (408) 2578652, will fix the problem -- but I tried and it
didn't work.
I'm wondering if anyone can recommend an alternate phone dialer --
preferable one that does not use a GUI like dialer.exe, which...
|
by: Oleg Ogurok |
last post by:
Hi there,
I have a modified ASP.NET TextBox control that formats its output as the
phone number, e.g. if you enter "1234567890" it'll change the value to
"123-456-7890". This is done by a javascript function called on "onblur"
event of the textbox.
However, it seems validation happens before the onblur event, therefore if I
enter "1234567890", the validator that checks the phone number is set to
"Invalid" state. How can I format the...
|
by: Brian Henry |
last post by:
I have phone numbers like this in a data table
123-435-1234
1231231234
432.234.2321
they all have different formatting, what I want to do is get them all
formatted like this
(123) 123-1234
|
by: womblesjc |
last post by:
I have a data bound Details View control in asp.net 2.0 that formats a
phone number. The 'Default Mode' for the control is set to Edit. The
phone number field is a template field and I can successfully call a
function that formats the phone number when the control is filled. But
when updating, the value being passed in to my format function is
vbNull instead of the value in the phone number field of the control.
How can I get the update...
|
by: venu |
last post by:
Hi,
I have a different requirement and it is :
I need to validate a phone number field.
It may or may not be a US phone number.
The constraints are :
***********************
# It should accept any number of numbers
| |
by: laredotornado |
last post by:
Hi,
Using php 4.4.4, I am looking to parse a US phone number string into 3
smaller strings -- area code, the first part of the phone number (3
digits) and the last part of the phone number (4 digits). The only
given is that there will be 10 digits in the string, but people may
include spaces, parens, or other characters. These are all strings
I'd expect
$p = "5558675309";
|
by: lim4801 |
last post by:
I am currently in doing a program which is given by my tutor:
Contemplate that you are working for the phone company and want to sell "special" phone numbers to companies. These phone numbers are "special" because they are easily translated into words. You've been asked to create a list of phone numbers that are directly mappable to words by searching a dictionary for every 7 or 10 letter word that maps on to the phone lettering scheme:
...
|
by: terryble |
last post by:
hy, We are deploying IPPhone cisco(R)
On this phone proprietary code exist with XML too.
After code modification, a can't find the final step for this service to work. I need to post the variable named "l" on the next page.
This variable is the Last name reference to search a name on a corporate directory.
here are the 2 pages of code
first it's a keyboard like html clickable picture it refere coordinates to zone from the TouchArea tag...
|
by: falconsx23 |
last post by:
I am trying to write a code for a Phone Directory program. This program is suppose to allow the user to enter a name or directory and then program can either add, save or even delete an entry. Also this program has more then one class and also uses an interface. Right now I am working on
ArrayBasedPD class. I am trying to write a code for the remove method (line 158) that allows the user to enter a name, once the program sees that the name is...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |