I'm trying to write a code for my computer programming class for a project due Monday, and I'm pretty new to Java, but I'm trying to write a program that will first determine if a number the user inputs is even or odd and then determine if the number is prime or not. I'm not sure if I did the algorithm right or not, so if anyone has any corrections on the program to my algorithm or anything else please say so, but my real issue is that the program is refusing to compile. Every time I try, it says it's having an else without if problem. Here's a link to my command box:
http://s1341.photobucket.com/user/Emi_Nightshade/media/Capture_zps45f9a2ea.png.html
Here's my code:
import java.io.*;
import java.util.*;
public class Lesson9p1_ThuotteEmily
{
public static void main(String args[])
{
Scanner kbReader0=new Scanner(System.in);
System.out.print("\n\nPlease enter an integer. An integer is whole number, and it can be either negative or positive. Please enter your number: ");
long num=kbReader0.nextLong();
if(num%2==0) //if and else with braces
{
System.out.println("Your integer " + num + " is even.");
}
else
{
System.out.println("Your integer " + num + " is odd.");
}
Scanner kbReader1=new Scanner(System.in);
System.out.print("\n\nWould you like to know if your number is prime? Please enter yes or no: ");
String yn=kbReader1.nextLine();
if(yn.equals.IgnoreCase("Yes"))
{
System.out.println("Okay. Give me a moment.");
{
if(num%2==0)
{
System.out.println("Your number isn't prime.");
}
else if(num==2)
{
System.out.println("Your number is 2, which is the only even prime number in existence. Cool, right?");
}
for(int i=3;i*i<=n;i+=2)
{
if(n%1==0)
{
System.out.println("Your number isn't prime.");
}
}
else
{
System.out.println("Your number is prime!");
}
}
}
if(yn.equals.IgnoreCase("No"))
{
System.out.println("Okay.");
}
}
}
If anyone could help me out with this and also any problems I may have made elsewhere in the program, I'd be very grateful! Thanks.
Is there any pitfalls when using char*'s to write cross platform code that does memory access?
I'm working on a play memory allocator to better understand how to debug memmory issues. I have come to believe char*'s are preferable because of the ability to do pointer arithmetic and derefernce them over void*'s, is that true? Do the following assumptions always hold true on different common platforms?
sizeof(char) == 1
sizeof(char*) == sizeof(void*)
sizeof(char*) == sizeof(size_t)
There are two tables:
Products
ID (Primary Key),
ProductName
PlannedByMonths
ProductID (Primary Key) (Link to the Products table many-to-one),
MonthNumber (Primary Key),
QtytoProduce,
How to write SELECT statement to retrieve results in the following format?
ProductName, QtytoProduceMonth1, QtytoProduceMonth2, QtytoProduceMonth3, QtytoProduceMonth4, QtytoProduceMonth5, QtytoProduceMonth6, QtytoProduceMonth7, QtytoProduceMonth8, QtytoProduceMonth9, QtytoProduceMonth10, QtytoProduceMonth11, QtytoProduceMonth12
Thank you.
Hi,
I have two tables table1 and table2, i need to write a select query which will list me the columns that exist in both the tables.(mysql)
I need to do for different tables (2 at a time)
Is this possible?
I tried using INFORMATION_SCHEMA.COLUMNS but am not able to get it right.
I have to write a drop down query for countries.
But USA hould always be first.
The rest of the countries are in alphabetical order
I tried the following query
SELECT
countries_id
,countries_name
FROM get_countries
WHERE
countries_id = 138
UNION
SELECT
countries_id
,countries_name
FROM get_countries
WHERE
countries_id != 138
ORDER BY 2 ASC
how would i manually add two chars without using the strncopy function?
can i just say char1 + char2?
or would i have to write a for loop to get individual elements and add them like this:
addchar[0] = char1[0];
addchar[1] = char1[1];
etc
etc
addchar[n] = char2[0];
addchar[n+1] = char2[1];
etc
etc
I hear about it a bit in tutorials that I watch, that certain things won't work if javascript is disabled. Occasionally I see workarounds.
The question is, are these relevent? I can't imagine anyone not having a javascript enabled browser nowadays, except the most ancient of phones, and chances are your page won't render on them properly anyway.
Do people still bother to write backup code for javascript being disabled?
Is there a built in equivalent to the .NET framework's DateAdd or AddMonths functions?
I'm looking for the easiest, cleanest way to add X month to a Javascript date.
I'd rather not handle the rolloing over of the year as done here.
or have to write my own function as done here.
Is there something built in that is as nice as the .NET Date.AddMonths function? Or something close?
I dont have perl install on windows. I would like to copy the entire testdb to testdb on my linux VM. What is the easiest way to do that? I can run code on my windows machine to connect to both DB and do sql operations. I am using C#.NET so if i need to write code and its simple then i'm open to that.
I was trying to add a method to the String class. This method should mutate the current string (of course it would be possible to write a not mutating version but I'd prefer the mutating one). I had no idea how to do this and after some googling I found the method rb_str_modify which makes a given string mutable. That's exactly what I need but I couldn't find an equivalent in the Ruby language. Did I miss something or is there really no possibility in the language itself?
hello
Is there library/header already written to manage C++ objects from C using opaque pointers/handles?
I can write one myself, but I would rather use already made solution, especially if it has fortran bindings.
Thanks
Probably a stupid question, but I can't find any documentation anywhere for it. Is there a way to do an if in prolog, e.g. if a variable is 0, then to do some actions (write text to the terminal). An else isn't even needed, but I can't find any implementation of if.
A matrix is diagonally dominant (by rows) if its value at the diagonal is greater then the sum of all absolute value in that row. Same goes for columns, only the other way around.
Is there a function in matlab for chekcing this ? (I could write a simple loop, but I'm trying to quit those).
I want to write a program to implement an array-based stack, which accept integer numbers entered by the user.the program will then identify any occurrences of a given value from user and remove the repeated values from the stack,(using Java programming language).
I just need your help of writing (removing values method)
e.g.
input:6 2 3 4 3 8
output:6 2 4 8
I have a handful of queries I need to write in SQL Server 2005. Each Query will be calculating 4 unit cost values based on a handful of (up to 11) fields. Any time I want 1 of these 4 unit cost values, I'll want all 4. Which is quicker? Computing in the SQL Query ((a+b+c+d+e+f+g+h+i)/(j+k)), calling ComputeScalarUnitCost(datapoint.ID) 4 times, or joining to ComputeUnitCostTable(datapoint.ID) one time?
I'm a beginner and I want to write Java code in eclipse. This program takes two LinkedLists of integers (for example, a and b) and makes a LinkedList (for example d) in which every element is the sum of elements from a and b. However, I can't add these two elements from a and b because they are Objects
Example:
a=[3,4,6,7,8]
b=[4,3,7,5,3,2,1]
------
d=[7,7,13,12,11,2,1]
I'm developing an NSIS installer, to update a program that runs in background. Obviously, I'd like to send the program termination signals, because otherwise I repeatedly get a "can't write" error. How can I do this, with a limited overhead on installer size?
Given a String array such as this:
string[]={"bmw"," ","1bmw"," "};
I need to count how often the substring bmw occurs in that array. In this example it occurs 2 times.
How do I write that in C#?
In an class header I have seen something like this:
enum {
kAudioSessionProperty_PreferredHardwareSampleRate = 'hwsr', // Float64
kAudioSessionProperty_PreferredHardwareIOBufferDuration = 'iobd' // Float32
};
Now I wonder what data type such an kAudioSessionProperty_PreferredHardwareSampleRate actually is?
I mean this looks like plain old C, but in Objective-C I would write @"hwsr" if I wanted to make it a string.
I want to pass such an "constant" or "enum thing" as argument to an method.
input
23 3 4 4 42 n 23 0 9 9 n n n 3 9 9 x
//according to input,i should create int pointer arrays. pointer arrays starting from 1 (that is initial arrays is arrays[1].when program sees n ,it must be jumb to arrays 2
expected output
arrays[1] 3 4 5 42
arrays[2] 23 0 9 9
arrays[5] 3 9 9
x is stopper
n is comman to create new pointer array
i am new in this site
anyone help me how can i write
Hi
I am trying to write a macro that would "click" a command button that is in another workbook.. Would that be possible? Without changing any of the code within that other workbook?
Thanks a lot!
Hi!
I´m trying to write a log system for my CakePHP intranet. What i need is to store de username/datetime whene someone tryes to login.
My login code is on the clients_controller and i need to store the data on a model called log (i have the model, controller, view... but they are not related)
how can i achive that?
thank you