473,468 Members | 1,586 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

2 variables in 1 "if" (new to java)

2 New Member
so the program wants me to output the a word based on what the punctuation the user used to end the sentence.
This is what i have so far, i know its really bad...
Expand|Select|Wrap|Line Numbers
  1. public class punctuation
  2. {
  3.     public static void main(String[] args)
  4.     {
  5.         int sentence, length, even=%2, odd=%1;
  6.         char question=?, exclamation=!, other=.;
  7.  
  8.         System.out.println("Enter a sentence.");
  9.         sentence = SavitchIn.readLineInt(); 
  10.         int length = sentence.length()
  11.  
  12.         if ( length == even , question)
  13.             System.out.println("YES");
  14.         else (sentence%1 == odd, question)
  15.             System.out.println("NO");
  16.         if (exclamation)
  17.             System.out.println("WOW");
  18.         if (other)
  19.             System.out.println("You always say" + sentence);
  20.  
  21.         System.out.println("Press enter key to end program.");
  22.         String junk;
  23.         junk = SavitchIn.readLine();
  24.     } 
  25. }
Sep 7 '10 #1
2 1384
Dheeraj Joshi
1,123 Recognized Expert Top Contributor
Above code do not make any sense it is not a valid java code.

Expand|Select|Wrap|Line Numbers
  1. even=%2
  2.  
% is not allowed when you declare and initialize the variables.
You can do find modulo of an declared variable.
Expand|Select|Wrap|Line Numbers
  1. int even=10;
  2. even = even%2;
  3.  
Expand|Select|Wrap|Line Numbers
  1. char question=?;
  2.  
char variables must be enclosed within the single quotes.
Expand|Select|Wrap|Line Numbers
  1. char question='?';
  2.  
Expand|Select|Wrap|Line Numbers
  1. if ( length == even , question)
  2.  
You can not compare the integer and character values like above.

And what is SavitchIn? Are you using any custom API's?
Expand|Select|Wrap|Line Numbers
  1. SavitchIn.readLineInt(); 
  2.  
Is this a wrapper for System class API's?

I suggest you read the JAVA syntax and programing basics to fine tune the program. So that it would at least compile.

Regards
Dheeraj Joshi
Sep 7 '10 #2
brodyvon
2 New Member
Thanks for the help really appreciate it.
Sep 7 '10 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

9
by: LRW | last post by:
I'm not exactly sure how to even ask the question, and I know my terminology is not good as I'm a SQL beginner, but, here goes. I need to find a way to make an if statement within an array...or,...
9
by: Scott Beavers | last post by:
I'm trying to create a form in Excel to sort from the form and take the data to another worksheet. I am very new to this and any help would be appreciated. I have a value in a cell that will...
40
by: Steve Juranich | last post by:
I know that this topic has the potential for blowing up in my face, but I can't help asking. I've been using Python since 1.5.1, so I'm not what you'd call a "n00b". I dutifully evangelize on the...
3
by: gamerman0203 | last post by:
I'm new to asp so this could be an obvious answer. how would I write and "if-then-else" statement in vbscript for my asp pages? what I'm doing is pulling data from an access db and displaying...
35
by: David Cleaver | last post by:
Hello all, I was wondering if there were some sort of limitations on the "if" statement? I'm writing a program which needs to check a bunch of conditions all at the same time (basically). And...
3
by: sapnsapn | last post by:
Hi folks, I am looking at an application written in C some 10+ years ago. There is a lot of such if statements: if (my_number) {....} else {...} Here, my_number is an unsigned int. What exactly...
4
by: Miguel Dias Moura | last post by:
Hi, i have this code line in a script in my ASP.net / VB web site: dim msgNewsletterAction msgNewsletterAction = Request.Form("newsletterAction") if msgNewsletterAction = "go" Then Code1
1
by: tomy | last post by:
Hi Group: The confusing code is as below: //------------------------------------------------- #if #define FOO foo #else #define FOO foobar #endif...
6
by: Jacob.Bruxer | last post by:
Hi, I'm pretty new to Visual Basic and programming in general. I want to know if it's possible to create an If statement that asks if a value is an integer. If it's an integer it does one thing,...
2
by: marsarden | last post by:
write code like: int main(void) { int a=10; if(a<20) {} } Compiler ok on dev-cpp . don't we have to add a ";" after if
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
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,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
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...
1
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...
1
isladogs
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.